Here I'm trying to ssh to multiple servers remotely and check whether any processes running on those servers and wait until the process to get finished.
while read ip name
do
process=alive
while [[ "$process" == "alive" ]]
do
process=dead
(if [ 1 -eq "$(echo "$(ssh ubuntu@$ip "top -b -n2 -d 0.5|grep Cpu|awk '{print \$2+\$4}'|tail -n1") > 1" | bc)" ];then
echo "Process is running on $ip"
process=alive
sleep 10
continue
else
echo "Process is not running on $ip"
echo "I run some other commands here"
fi) &
done
done < ips
wait `jobs -p`
The code is breaking after 'continue' statement.
Here is the output
+ read ip name
+ process=alive
+ [[ alive == \a\l\i\v\e ]]
+ process=dead
+ [[ dead == \a\l\i\v\e ]]
+ read ip name
+ process=alive
+ [[ alive == \a\l\i\v\e ]]
+ process=dead
+ [[ dead == \a\l\i\v\e ]]
+ read ip name
++ jobs -p
++ bc
+ wait 31090 31091
+++ ssh [email protected] 'top -b -n2 -d 0.5|grep Cpu|awk '\''{print $2+$4}'\''|tail -n1'
++ bc
+++ ssh [email protected] 'top -b -n2 -d 0.5|grep Cpu|awk '\''{print $2+$4}'\''|tail -n1'
++ echo '20.7 > 1'
+ '[' 1 -eq 1 ']'
+ echo 'Process is running on 249.X.X.X'
Process is running on 249.X.X.X
+ process=alive
+ sleep 10
++ echo '14.6 > 1'
+ '[' 1 -eq 1 ']'
+ echo 'Process is running on 256.X.X.X'
Process is running on 256.X.X.X
+ process=alive
+ sleep 10
+ continue
+ continue