SSH only fires for first server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SSH only fires for first server
# 1  
Old 04-27-2009
SSH only fires for first server

I have a shell script I have been working on that reads a dat file which contains a list of server name. It takes each server and attempts to ssh to it and then runs a command. The probelm is that its only doing the ssh to the first server in the list.

Here is the code...
Code:
exec 0</lcl/sit/apps/Tivoli/netcool/omnibus/scripts/postevent_scanner/test.dat
while read line
do
echo $line
x=1
/usr/sbin/ping $line
x=$?
if [ $x = '0' ]; then
ssh -n $line "/lcl/apps/esm/bin/postEvent.pl -s 30 -m '*** PostEvent.pl Test From Server: $line ***' -g 'INFR_Apps' -t 'None'" &
fi
done

And here is the output....
Code:
sentra
sentra is alive
scylla
scylla is alive
[Mon Apr 27 09:25:36 2009] [INFO] Message sent to Tivoli, *** PostEvent.pl Test From Server: sentra ***

As you can see only the the first server (sentra) did the ssh.

Not sure what I am doing wrong here... Any ideas? Thanks
# 2  
Old 04-27-2009
Does your script exit or just sit there?

I've done lots of ssh remote commands within scripts and it can get a bit manic.

Heres what i do for a system to just go and get info from a file to then use as a file list for rsync. I've just pasted the relevant sections. Obviously the log variables you can remove or set as you wish.

Code:
# RSYNC_OPTS :
#       May want to drop the v verbose
#       R - relative makes the source dirs under dest
#       q - quiet reduced output
#       a - archive, keeps file permissions etc
#       --delete        Deletes files on destination if removed from source
#       --numeric-ids   keeps file uids as source and doesnt match to
#                       destination users/groups with same uid
# SSH_OPTS :
#       ConnectTimeout=15
#                       Causes ssh to quit if not connected withint 15secs
#       StrictHostKeychecking=no
#                       Causes ssh to NOT ask for yes/no if the remote_server
#                       host key is unknown which causes the script to fail
#       LogLevel=quiet  Surpresses the banner information
#       -n              Prevents reading from stdin. Without this ssh overrides
#                       the current process (i.e the script) with itself.
#                       Used so ssh can run in the background
#       BatchMode=yes   Passphrase/Password querying will be disabled

# [ Binary Vars ]
#RSYNC_BIN=$(/usr/bin/which rsync)      #May want to set explicitly
RSYNC_BIN="/usr/local/bin/rsync"
#RSYNC_OPTS=" -PaRz --quiet --stats --delete --delete-excluded --copy-unsafe-links --numeric-ids"
RSYNC_OPTS=" -aRz --partial --quiet --stats --delete --delete-excluded --copy-unsafe-links --numeric-ids"
RSYNC="${RSYNC_BIN} ${RSYNC_OPTS}"      #May want to set explicitly
#SSH_BIN=$(/usr/bin/which ssh)
SSH_BIN="/usr/local/bin/ssh"
SSH_OPTS=" -i ${NOVAB_LOC_SSH_KEY} -o ConnectTimeout=15 -o BatchMode=yes -o StrictHostKeyChecking=no -o LogLevel=quiet"
SSH="${SSH_BIN} ${SSH_OPTS}"
SED=/usr/bin/sed
EGREP=/usr/bin/egrep
TEE=/usr/bin/tee
AWK=/usr/bin/awk


....within a connection test function i have this bit ....


# There wont be any yes/no question to ssh and it will
# time out on a problem server as we have used various ssh options.
# NOTE: -n is so important here.
# SSH options are explained with Variable explanations
con_server=$1
con_mainlog=$2
con_errorlog=$3

# con_test parses the config file also
#
# Main connection test and set variable as file list
# to backup if successful.

echo "\n[Con_Test for ${con_server}]" >> ${con_mainlog}
con_test_res_list=$( ${SSH} -n -l root ${con_server} 2>> ${con_errorlog} "/usr/bin/awk '/(^\/)/ {print "\$1"}' ${REM_BK_LOC_FILE}" )

# Now return file list to function call or blank if error
echo ${con_test_res_list}

Hopefully you can get something from that and make it work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

How to ssh from an AIX OS server to a Fabric OS server without password?

Hi I'd like to ssh from an AIX OS server ( v5.3) to a Fabric OS server ( v6.1.2 ) without password. I tried using dsa or rsa keys but it didn't work, the aix server still asked for the password. Somebody help, please :(:(:( (8 Replies)
Discussion started by: bobochacha29
8 Replies

2. Shell Programming and Scripting

Multi server access through remote server using ssh

Team, Presently I have 5 ip address kept in ip_abc1 file, for each of the ip address listed, i need to login on each ipaddress one at a time and login as below for that specific ip address ssh -p 8101 karaf@<ip.address_for the specific ip address as logged in> password features:list... (4 Replies)
Discussion started by: whizkidash
4 Replies

3. Shell Programming and Scripting

Ssh to get files from server A and zip in server B

Hi, I have read & write access in Unix box A and read access in Unix box B. I want a folder to be zipped from box B and sftp-ed in box A. Is there a remote scripting to achieve this? (2 Replies)
Discussion started by: Prasannag87
2 Replies

4. Shell Programming and Scripting

Connect (SSH) to Windows server via Linux server through a script and passing command.. but failing

I am trying to connect to Windows server via Linux server through a script and run two commands " cd and ls " But its giving me error saying " could not start the program" followed by the command name i specify e g : "cd" i am trying in this manner " ssh username@servername "cd... (5 Replies)
Discussion started by: sunil seelam
5 Replies

5. Cybersecurity

ssh to terminal server

Hi. We are currently upgrading the terminal server in our system (Solaris 8). Previously, we used telnet to reach the terminal server from our maintenance workstation. Now, the new one supports SSH, so we're finally moving off telnet. When logging into the terminal server via telnet, a user was... (3 Replies)
Discussion started by: jalburger
3 Replies

6. Cybersecurity

ssh to terminal server

Hi. We are currently upgrading the terminal server in our system (Solaris 8). Previously, we used telnet to reach the terminal server from our maintenance workstation. Now, the new one supports SSH, so we're finally moving off telnet. When logging into the terminal server via telnet, a user was... (0 Replies)
Discussion started by: jalburger
0 Replies

7. Shell Programming and Scripting

Using ssh to add register key on ssh server

Hi, I want to use ssh to add a register key on remote ssh server. Since there are space characters in my register key string, it always failed. If there is no space characters in the string, it worked fine. The following is what I have tried. It seems that "ssh" command doesn't care about double... (9 Replies)
Discussion started by: leaftree
9 Replies

8. HP-UX

How to ssh HP UX server

Hi All, I m having Integrity rx4640 model server with me. I want to ssh to that server. Kindly provide solution that i can I SSH to that server. Its urgent (1 Reply)
Discussion started by: sunray
1 Replies

9. Cybersecurity

What's the difference between an SSH Client and an SSH Server?

Eh... yeah. What the title says. :D (1 Reply)
Discussion started by: PSC
1 Replies

10. UNIX for Dummies Questions & Answers

shell or admin fires the db

Q for the admin guys, When the server (Spark) is rebooted does a shell starts database, connection to database, and etc or would have to be the administrator log on as database admin and start the database? If it starts from the shell how would the script look like since the dba has access to the... (1 Reply)
Discussion started by: softarch
1 Replies
Login or Register to Ask a Question