SSH Process monitoring and Exit Status evaluation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SSH Process monitoring and Exit Status evaluation
# 1  
Old 05-18-2012
SSH Process monitoring and Exit Status evaluation

Hi All,
I have a peculiar requirement as follows,
I have a some hosts on which i have to run a script, so i am using the following code piece
Code:
for i in $HOSTLIST
do
  ssh ${i} "~/task.sh"
done

Now i want to run this same thing in parallel on all the hosts and then monitor the ssh process and also get the appropriate process exit status and i want to log the same so i tried the following
Code:
for i in $HOSTLIST
do
  ssh ${i} "~/task.sh"
  echo "${i}:$!" > process.file
done
 
for line in `cat process.file`
do
   #Assuming i have extracted pid value using cut
   pid=`echo ${line}|cut -d ":" -f2`
   wait "${pid}"
   echo "$? - Status for ${pid}" > Status.file 
done

The error i am getting now i sthe status is alwaus logged as 127 and the log shows
wait: pid <PID> is not a child of this shell

Also the ssh script is run in flow as follows
1.sh -> 2.sh ->3.sh(script which has ssh code in it)

Any help on this will be highly appreciated...

TIA

---------- Post updated at 02:52 PM ---------- Previous update was at 02:33 PM ----------

Anyone has any idea about it?
# 2  
Old 05-18-2012
I highly recommend the pdsh tools which greatly facilitates this kind of thing. I really think this will solve most of your problems.

Anyway, the main problem is that you are not putting the processes into the background.

Which shell are you using? Is it bash? if so, which version?
This User Gave Thanks to otheus For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Ssh script to validate ssh connection to multiple serves with status

Hi, I want to validate ssh connection one after one for multiple servers..... password less keys already setup but now i want to validate if ssh is working fine or not... I have .sh script like below and i have servers.txt contains all the list of servers #/bin/bash for host in $(cat... (3 Replies)
Discussion started by: sreeram4
3 Replies

2. Shell Programming and Scripting

Want to get the exit status

Hi All, I am trying to create a zip file with all the txt files(these are in large number) in the current directory. I am able to do this operation sucessfully. After this i want to get the status of the tar command executed and do accordingly. When i am trying with the below code, the status... (3 Replies)
Discussion started by: paddu
3 Replies

3. Shell Programming and Scripting

Test exit status of last cmd via ssh

see below for a housekeeping script which constructs an ssh cmd using some server/path/sudo info found in $HRINST. the script should hop to each server and if it finds a file to cleanup, moves it to the archive dir if there is nothing to move, it should report so and email the output ... (3 Replies)
Discussion started by: jack.bauer
3 Replies

4. Shell Programming and Scripting

How to test for the ssh exit status in script?

Hello; I regularly run monitoring scripts over ssh to monitoring scripts But whenever a server is hung or in maintenance mode, my script hangs.. Are there anyways to trap exit status and be on my way ?? Looked at the ssh manpage and all I can see is a "-q" option for quiet mode .. Thank... (2 Replies)
Discussion started by: delphys
2 Replies

5. Shell Programming and Scripting

Exit Status

I have a shell script (#!/bin/sh) that interacts with Appworx and Banner Admin. In my script I want to check the exit status of awrun before continuing. awrun can run for 10 seconds or it can run for over a minute. So my question is, will it go through my if statement before awrun may even be... (2 Replies)
Discussion started by: smkremer
2 Replies

6. HP-UX

[Solved] ssh debug1: Exit status 254 problem

Hello; Am experiencing odd problem with ssh: ========= ssh -vvv remote_host : : debug2: channel 0: rcvd adjust 65536 debug2: channel_input_status_confirm: type 99 id 0 debug2: shell request accepted on channel 0 debug1: client_input_channel_req: channel 0 rtype exit-status reply 0... (4 Replies)
Discussion started by: delphys
4 Replies

7. Shell Programming and Scripting

how to exit status of a piped process ???

Hi, I've searched the related threads both in this forum and others in google and found the solution to be working too in most of the places. But somehow it's not working for me. $cmd | tee -a $LOGFILE & pid=$! wait ${pid} ret=$? echo "$ret" I want the exit status of the $cmd.... (8 Replies)
Discussion started by: ashwini.engr07
8 Replies

8. Shell Programming and Scripting

Exit status

I'm preparing for exam and one of exams is to write own test command... I wonder if in unix is a command which just returns exit code you specify.. I know I can easily write a function like this: exStatus() { return $1 } -> my question is rather theoretical thank you! (9 Replies)
Discussion started by: MartyIX
9 Replies

9. Shell Programming and Scripting

How to get the exit status

Hi all, I'm running a program which return 1 upon success. But when encounters problem shell return 's '1' . How to differentiate between them the shell return value and script return value. Ex. function fn return '1' if executed successfully and '0' if failed. But when if shell encounters... (1 Reply)
Discussion started by: yhacks
1 Replies

10. Shell Programming and Scripting

exit status

i downloaded a text file from metalab.unc.edu called sh.txt and in this reference manual it refers to shell scripting exit status .. at the end of one of the examples that author gave an exit status of 127.. to what does a 127 exit status refer too and what is its purpose in the code. moxxx68 (1 Reply)
Discussion started by: moxxx68
1 Replies
Login or Register to Ask a Question