Computing.Net > Forums > Unix > Script to remotely logon to server

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Script to remotely logon to server

Reply to Message Icon

Name: red2009
Date: February 24, 2009 at 11:17:28 Pacific
OS: Unix
Subcategory: Software Problems
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: red2009
Date: February 24, 2009 at 13:18:27 Pacific
Reply:

Okay I found if I do a
cat scriptname | ssh serverB

It 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?


0

Response Number 2
Name: nails
Date: February 24, 2009 at 15:49:51 Pacific
Reply:

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


0

Response Number 3
Name: sureshht
Date: March 17, 2009 at 07:27:38 Pacific
Reply:

Hi,

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

Thanks
Suresh

sureshht


0

Response Number 4
Name: red2009
Date: March 17, 2009 at 13:42:04 Pacific
Reply:

Try this

ssh name@hostname command

example ssh xyz@abc ls -ltr /


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Script to remotely logon to server

Remote script to chmod www.computing.net/answers/unix/remote-script-to-chmod/7397.html

Script to send email if Unix reboot www.computing.net/answers/unix/script-to-send-email-if-unix-reboot/4576.html

Script to auto login to telnet session www.computing.net/answers/unix/script-to-auto-login-to-telnet-session/2854.html