I have a server that i can ssh into from my laptop.
I want to be able to run a script on my laptop that sends a signal to the server which makes the server initiate a given script there.
How do I do that?
Or,if you only want to run command2 if command1 succeeded, and command3 if command2 succeeded:
Note that you'll need to pay special attention to shell quoting issues, they can become very complicated when you're typing a command in your local shell to execute commands on a remote shell (they can get bad enough even just working with a local shell). For example, consider the difference between the following two commands:
The first prints only the PIDs of sshd processes. The second prints the full A third option is to run the ps on the remote host and the awk locally:
In the two commands above, the entire quoted string is executed on the remote host, because that's the argument you've given to the ssh command. In this example, everything up to the | is executed remotely (again because 'ps', 'hu', and '-Csshd' are args to the ssh command, and the remainder of the line is executed locally. For tasks that are more complicated than you want to run with a one-liner (or when the shell-quoting becomes hellish), you can write a shell script and copy it to the remote host, then execute it with ssh:
You can copy the script to anywhere you like, but a) you need write access to the directory, b) it can't be on a filesystem mounted with noexec (not common but sometimes /tmp is mounted noexec) unless you run it with "/path/to/interpreter /path/to/script" - e.g. |
|||
|
|
ssh you@yourserver lsand see what it does. – Mat Jul 28 '12 at 14:45