![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Sorry if I made this confusing..
Test code: Code:
#!/bin/sh ssh -q root@hostname test1.sh Please let me know if anyone has a solution for this. Thanks! nua7 |
|
#3
|
|||
|
|||
|
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 Code:
#!/bin/sh answer=$(ssh host "tail -1 /path/temp_file") [ $answer != "finish" ] && break || echo "Do something else" |
|
#4
|
|||
|
|||
|
Thanks a lot Danmero! This would help me a lot!
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|