The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Setting environment variable on a remote solaris machine using shell script eamani_sun Shell Programming and Scripting 1 05-30-2008 07:05 PM
how to execute a script on remote machine balireddy_77 Shell Programming and Scripting 4 09-27-2006 04:45 PM
checking exit status of a shell script kdipankar Shell Programming and Scripting 2 05-08-2006 10:08 PM
Need Script to check whether user exists in the remote machine Srini75 SCO 1 09-07-2005 08:23 AM
Checking the exit status of ftp psingh UNIX for Advanced & Expert Users 1 06-04-2002 07:51 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-23-2008
Registered User
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 352
Checking the status of the script on remote machine

Hi!
I have a script, which calls another script on a remote machine using ssh.
I need to check if the remote running script is succesful. If it is succesful I need to continue the for loop (run it on another machine) or break the loop.
Please let me know if anyone has an idea on checking the status of the script on remote machine .

My script is as below.

./sshlogin.exp $passw $host $username statement would trigger the second script on a remote machine.
Code:
#!/usr/bin/sh
##Take input from the user
c=d=e=0
while [ "$host_name" != done ] 
do
  echo "Please enter the host_name"
  read host_name
  if [ "$host_name" = done ] ; then break; fi
  store_hostname[$c]=$host_name
    #Check if hostname is correct
  validHost=`host $host_name | grep 'not found'`
  if [ "$validHost" != "" ] ; then
  echo "Checking Host" 'Host cannot be resolved. Please check your hostname'
  exit 1
  fi
  c=$(( c + 1 ))
  echo "Please enter the username"
  read username
  store_username[$d]=$username
  d=$(( d + 1 ))
   echo "Please enter the password"
   read -s password
   store_password[$e]=$password
   e=$(( e + 1 ))
done
echo ${store_hostname[0]} 
len=${#store_hostname[*]}
echo $len
for (( i=0; $i < $len; i++ ))
do
host=`echo ${store_hostname[$i]}`
passw=`echo ${store_password[$i]}`
username=`echo ${store_username[$i]}`
ssh -q host@username date
./scplogin.exp $passw $host $username
./sshlogin.exp $passw $host $username
if [ "$?" = 1 ] ; then break; fi
done
Reply With Quote
Forum Sponsor
  #2  
Old 07-23-2008
Registered User
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 352
Sorry if I made this confusing..

Test code:

Code:
#!/bin/sh
ssh -q root@hostname test1.sh
How can I check if the test.sh script has completed successfully.
Please let me know if anyone has a solution for this.

Thanks!
nua7
Reply With Quote
  #3  
Old 07-23-2008
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 736
Use a "temp" file or a .log file on remote.
Code:
#!/usr/bin/sh
echo "running" >> /path/temp_file
...
do_something
...
#on exit
echo "finish" >> /path/temp_file
On your local check remote
Code:
#!/bin/sh
answer=$(ssh host "tail -1 /path/temp_file")
[  $answer != "finish" ] && break || echo "Do something else"
From here you can use your imagination
Reply With Quote
  #4  
Old 07-23-2008
Registered User
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 352
Thanks a lot Danmero! This would help me a lot!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 02:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0