Checking the status of the script on remote machine


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking the status of the script on remote machine
# 1  
Old 07-23-2008
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

# 2  
Old 07-23-2008
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
# 3  
Old 07-23-2008
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 Smilie
# 4  
Old 07-24-2008
Thanks a lot Danmero! This would help me a lot!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check/get the exit status of a remote command executed on remote host through script

Geeks, Could you please help me out in my script and identify the missing piece. I need to check/get the exit status of a remote command executed on remote host through script and send out an email when process/processes is/are not running on any/all server(s). Here's the complete... (5 Replies)
Discussion started by: lovesaikrishna
5 Replies

2. Shell Programming and Scripting

Checking LB status.. stuck in script syntax of code

#!/bin/ksh #This script will check status of load balancer in AIX servers from hopbox #Steps to do as folows : #Login to server #netstat -ani | grep <IP> #check if the output contains either lo0 OR en0 #if the above condition matches, validation looks good #else, send an email with impacted... (7 Replies)
Discussion started by: vinil
7 Replies

3. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

4. Shell Programming and Scripting

Shell Script for continuously checking status of a another script running in background, and immedia

Hi, I want to write a script which continuously checking status of a script running in background by nohup command. And if same script is not running then immediately start the script...please help.. i am using below command to run script nohup system_traps.sh & but in some... (9 Replies)
Discussion started by: ketanraut
9 Replies

5. Shell Programming and Scripting

Script for SFTP Status Checking

Greetings... I have to construct shell script to check the SFTP status, Define a global variable (say sftpStatus). Set it to default value "success" when you define it first time outside the script. check the current SFTP status (say currentStatus - local variable within the script) if... (16 Replies)
Discussion started by: manju98458
16 Replies

6. Solaris

Checking the port status of a remote host

Hi there I am in the process of writing a script to check whether a port on a remote system is up or not. Here's what I have so far: #!/bin/bash telnet xx.xx.xx.xx 80 | (echo "^]") if ]; then echo "Please check Web services " | mailx -s "Please check webservices... (1 Reply)
Discussion started by: notreallyhere
1 Replies

7. UNIX for Advanced & Expert Users

Script running on remote machine - How ??

Hi All, This was an interview question " There is a clean-up shell-script in one UNIX machine and it is connected to 100 other UNIX machines. Howe can we run the script on all the 100 machines without ftping/copying the script to target machines ? I was unable to answer, please answer if... (5 Replies)
Discussion started by: coolbhai
5 Replies

8. UNIX for Advanced & Expert Users

Running script on remote machine

if i have a script in my system which i need to run on remote system using ssh, how shall i do it? One easy way to to first scp it to remote machine and then run it on remote machine using ssh. Is there any one step way to do it. Preferably one in which i should give password only once (3 Replies)
Discussion started by: vickylife
3 Replies

9. Solaris

To invoke a script on a remote machine

Hi, I am trying the following- 1. ftp a file from machine1 to machine2. 2. Once the ftp is done, from machine1 invoke a shell script on machine2. Could anyone please help me on this? (5 Replies)
Discussion started by: sam_roy
5 Replies

10. Shell Programming and Scripting

checking exit status of a shell script

Hi, I have tried with the following code; if ;then echo "Failure." else echo "Success." fi to test the exit status of the test.ksh shell script. But whatever is the exit status of the test.ksh shell script Failure. is always printed. Please help. regards, Dipankar. (2 Replies)
Discussion started by: kdipankar
2 Replies
Login or Register to Ask a Question