Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ssh to another server using a script

Status
Not open for further replies.

mmcds

MIS
Jul 5, 2007
28
US
I am using 2 linux servers, serverA and serverB for example. I am writing a script on serverA to run a couple of commands and then I want the script to automatically ssh over to the serverB to run a couple commands on serverB. How can I do that with a script to ssh over to the serverB and login? If I am on serverA and type ssh (server name) at the command prompt, then it will connect and just ask for my password and it allows me onto my serverA machine. Thanks in advance for any help.
 
OK. I got it so it doesn't ask for passwords through ssh, but now how can I make it cd to a directory for example and run a script that is on the other server? For example, say on the server testserver2 I have a script in /scripts/test called testit.sh. I am currently on testserver1 where I will kick off a script on there to do a couple of things and then have it ssh to the testserver2 to run the testit.sh script over there?
 
Something like:

[tt]ssh testserver2 'cd /scripts/test && ./testit.sh'[/tt]

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top