Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello Everyone,
I am trying to write a script which remotely logons to a server without prompting password. Then sudo to a particular user and execute few unix commands on that server.
I am just looking for pointers as I am very new to scripting. The script is on A server and when I run on A server, it remotely logs on to B server without password prompt. Till here its going okay. But after that I loose connection to server A and hence the script on server A, so nothing goes beyond that. How can I acheieve to run a script on server A which log on to server B and runs few commands on server B.
I hope I have not made it very confusing. I know I am missing some critical thing. Any answers are greatly appreciated.
-Thanks

Okay I found if I do a
cat scriptname | ssh serverBIt runs the script on server B. when command prompt returns u r still on server A. This works for me.
Now the next question I have is, I want to run the script on 50 servers. I want to put the names of the servers in a flatfile and call the server names in the command or write a small script to do this. ( I dont want to execute the same command 50 times) Can anyone give me some hint on how to do go about doing it?

Assuming your servers are listed in file servers.txt, one per line:
#!/bin/ksh cd <to your directory where $servername exists> # untested while read server_name do # do your processing here: cat scriptname | ssh "$server_name" done < servers.txt

Hi,
If I want to execute only one line from the script on the remote server, How do I do it?
Thanks
Sureshsureshht

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |