login into multiple servers through script is having some problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting login into multiple servers through script is having some problem
# 1  
Old 10-03-2009
login into multiple servers through script is having some problem

Hi Everybody,

I am bit new to shell scripting. I need some help in my script.
I have to login into 15 servers and check some logs daily. For that I've written one shell script, somewhere it is having some problems. After log into the first server, the script is not going with the next steps. As I'm trying to run the script from my home directory, I guess, I don't need to provide any password to login to that server, and it's also not asking any passwds. I'm not getting what is wrong in the script?
The script is attached to this post.
Can anyone please help on this please?

Thank in advance..

Regards,
Raghu.
# 2  
Old 10-03-2009
despite issuing commands after ssh in your script, you are not actually passing those commands to the remote server. your script is instead waiting for that ssh command to return (i.e., logout) before continuing.

you can use a heredoc to pass the commands to the session, or you can put the script on the remote servers and call it as an argument to ssh

heredoc
Code:
ssh ${i} <<EOF
# put all commands to execute here
...
EOF

remote script
Code:
 ssh ${i} /path/to/myscript.sh

# 3  
Old 10-03-2009
Hello Raghu,

The first thing I noticed is that you put set -x in front of the shebang (!#). This means that it will not be processed, since it needs to be at the start of the first line.

The second thing is that you are using:

Code:
for i in `cat ${SERVER_LIST}`
do
ssh ${i}

Without specifying which command to execute on the remote server. So effectively you will just ssh to the first server in the list where you will be asked for input to the interactive shell you started there. When you then exit that shell the script will continue and process the script on the server you fired the script from, etc.

S.
# 4  
Old 10-03-2009
Hi Varontron/Scrutinizer,

Thanks for your suggestions steps, I followed your steps (I have given the heredoc <<EOF). It has executed successfully for first server only. After all the commands are executed in first server, the loop is going to end. The server_list file is like below,
cat server_list
server1
server2
server3
.....
.....
...
.

Is this file having any changes?
or
Is the loop statement having any changes?

New script is attached after some changes.

Please suggest on this,

Thanks,

Regards,
Raghu.
# 5  
Old 10-03-2009
put the final 'EOF' after 'exit'

otherwise you are exiting from the running script, not the remote session
# 6  
Old 10-03-2009
-superfluous-
# 7  
Old 10-03-2009
Thank you very much Varontron, it's working now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to check login across multiple servers

I need to manually interactively feed in my password for each server one after the other. Below is the script I am using: #!/bin/bash input="serverlist.txt" while IFS= read -r var <&3 do echo $var ssh user1@$var done 3< "$input" I get password prompt for the first server. If I dont have... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

Run a script on multiple servers

I need to run a script on a bunch of remote servers. how can this be done without ssh into each individual server and run it its under /sbin/script.sh on each server (1 Reply)
Discussion started by: tdubb123
1 Replies

3. Shell Programming and Scripting

Remote login and running a script on multiple servers

Hi all, I am baffled on this. Solaris Irix system.:confused: I have 4 servers all connected to one another, :b: I need to write a script line that would login on to server 1-3 ($HOST) start a script in the back ground and log off while the back ground script runs over a length of time.:eek: ... (10 Replies)
Discussion started by: weddy
10 Replies

4. Shell Programming and Scripting

Script for login to servers with user name and password and execute commands

I am having the 15 servers which need to do the monitoring Hi I need a shell script, By which i can log in to multiple servers and execute the commands.. I need to specify the username and password in the scripts. Please help me to write the script so that it can login with username and... (5 Replies)
Discussion started by: nandan8a
5 Replies

5. Shell Programming and Scripting

Script to login to several servers and get files

Hi ppl, I am looking out for a shell script a. That would have to login(from a main server) to say 16 servers individually. b.On each server go to a particular location, check if a particular file is generated on a date(say every sunday it gets generated and i would be interested in the latest... (8 Replies)
Discussion started by: yohasini
8 Replies

6. UNIX for Advanced & Expert Users

Script to login to several servers and get files

Hi ppl, I am looking out for a shell script a. That would have to login(from a main server) to say 16 servers individually. b.On each server go to a particular location, check if a particular file is generated on a date(say every sunday it gets generated and i would be interested in the latest... (1 Reply)
Discussion started by: yohasini
1 Replies

7. UNIX for Dummies Questions & Answers

Script to login to several servers and get files

Hi ppl, I am looking out for a shell script a. That would have to login(from a main server) to say 16 servers individually. b.On each server go to a particular location, check if a particular file is generated on a date(say every sunday it gets generated and i would be interested in the latest... (0 Replies)
Discussion started by: yohasini
0 Replies

8. Shell Programming and Scripting

Problem sshing to multiple servers while in a loop

I have the following block from a script (it's not the entire script, but I'm confident it's all that is pertinent) echo "$SESSIONS"|while read ID;do ASSETID=$(echo "$ERRORS"|grep -i "$ID"|grep FX_Media_Session_Playlist::init_playlist|grep -i asset_id=|awk '{print $11}') BLADE=$(echo... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

9. Shell Programming and Scripting

Shell/perl script to connect to different servers in single login in teradata

Hi, I want to write a shell script to compare two tables in teradata.these tables are present on different servers. I want to connect to both servers in single login in order to fetch and compare the data in one go. Thanks (1 Reply)
Discussion started by: monika
1 Replies

10. Shell Programming and Scripting

login into multiple servers thru script...

I need to login into multiple servers thru a script run couple commands and run find command as root. I only have ssh access to the servers as a user than I can "su" to root. If you have a similar script please post it. Also if you can suggest commands that I should consider please let me know. ... (1 Reply)
Discussion started by: avcert1998
1 Replies
Login or Register to Ask a Question