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.

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

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

remote script

 ssh ${i} /path/to/myscript.sh

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:

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.

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.

put the final 'EOF' after 'exit'

otherwise you are exiting from the running script, not the remote session

-superfluous-

Thank you very much Varontron, it's working now.