views:

547

answers:

3

As part of an intricate BASH script, I'd like to execute a command on a remote system from within the script itself.

Right now, I run the script which tailors files for the remote system and uploads them, then through a ssh login I execute a single command.

So for full marks:

  • How do I log into the remote system from the bash script (i.e. pass the credentials in non-interactively)?
  • How can I execute a command (specifically "chmod 755 /go && /go") from within the script?
+11  A: 

Set up SSH key pairs and just run the command like:

ssh user@host 'command'

There are, of course other interconnects available, but few portable.

Tim Post
+2  A: 

Following tinkertim's answer:

Setup public keys and then you can do the following:

#!/bin/bash
ssh user@host "chmod 755 /go && /go"
Nerdling
combine your answers and it's much more complete.
Jweede
A: 

Not really a direct answer to the question, but ...

You might want to have a look at Capistrano. Capistrano is developped to help you run commands on multiple machines. It might be too specialized for your needs ... but who knows ...

Guillaume