How do I send a command to a Linux box from a Windows box in a script?

1

The problem: I have a backup program (BackupAssist) that can run scripts automatically after a backup. I want to automatically shut down the computer that stores my offsite backups after the backup completes. I have the shutdown part working (with keys instead of passwords so it would work in a script), but I don't know how to send the Linux box a command without using an interactive shell like Cygwin.

I need to be able to send the command with no user interaction at all. A way to simply execute commands from Cygwin in scripts would be ideal, but any solution will do.

ChimneyImp

Posted 2012-06-13T20:53:16.613

Reputation: 1 149

Answers

2

plink is an ssh client for Windows.

You can also use the ssh client from OpenSSH from Cygwin.

You will need to have sshd running and available on your Linux machine. If you want to run automated, you probably want to use passwordless ssh keys for this.

Rich Homolka

Posted 2012-06-13T20:53:16.613

Reputation: 27 121

0

If you have access to ssh from Cygwin, then ssh user@host <command> will execute <command> in place of the login shell. Alternatively, you can use plink.exe from PuTTY in place of the Cygwin's ssh. (Thanks grawity)

You can also execute multiple commands, e.g.

ssh user@host "first_command ; second_command ; ..."

Darth Android

Posted 2012-06-13T20:53:16.613

Reputation: 35 133

2PuTTY has an equivalent, plink. – user1686 – 2012-06-13T21:12:21.347

@grawity Ah! All I had been able to find was PuTTY's -m argument, which seemed kind of clumsy for this. – Darth Android – 2012-06-13T21:17:33.803

0

If you want to run SSH in Cygwin from a batch file you could try:

@echo off
C:\cygwin\bin\bash ssh user@host 'shutdown -h now'

Fair warning, I don't have a Windows box to test this on.

Sam Whited

Posted 2012-06-13T20:53:16.613

Reputation: 145