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.

#!/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
 

Sorry if I made this confusing..

Test 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

Use a "temp" file or a .log file on remote.

#!/usr/bin/sh
echo "running" >> /path/temp_file
...
do_something
...
#on exit
echo "finish" >> /path/temp_file

On your local check remote

#!/bin/sh
answer=$(ssh host "tail -1 /path/temp_file")
[  $answer != "finish" ] && break || echo "Do something else"

From here you can use your imagination :cool:

Thanks a lot Danmero! This would help me a lot!