Quote:
Originally Posted by aggrishabh
Also is there any way we can move to next serer in list if command fail to execute in 5 or 10 sec without user intervention.
|
ssh will pass on the exit code of the remote program, but running screen remotely will eat that though it might allow time for the program to complete, if time is what it needs.
Keefaz' loop could be modified to use 'timeout'
Code:
for server in server1 server2 server3; do
ssh $server timeout -k 10 5 sed -i 's/^password.*/password --md5 NEW_PASS/' /boot/grub/grub.conf
echo Status was $?
done
That would send a TERM signal after 5 seconds to 'sed' if it is still running. Then if that didn't work it would send a KILL signal after 10 seconds. But if 'sed' ran to a natural completion its return code would be passed to the original shell, the one running the loop. If 'timeout' stops 'sed' then the exit code will be 124 or 137