
How I delay code execution in Bash until a remote host is responding
I have recently been working on some code that needs to run on a remote host using SSH. I describe this in my article, Using tar and ssh for backups.
But now I need to reboot the remote computer and wait until it has completely rebooted and the network is up and running. Only after that occurs can I continue sending commands to that remote system.
This little bit of code accomplishes that for me.
Host="f41vm"
X=1
until [ $X -eq 0 ] ; do
sleep 10s
ping -c1 $Host
X=$?
done
# The rest of the code is executed starting here,
# when the ping is successful and
# returns 0 instead of 1.
The X=$? statement takes the return code of the ping command ( $?_ ) and sets the $X variable to that value. Then $X can be used in the until statement comparison expression.
I add the sleep command so I’m not sending a Bazzillion pings to the remote host, and 10 seconds seems to work well enough for most of my purposes.
More Stories
A Small Algol 68 Project, Part 3
In memory of J. Kevin Douglas, a good friend and fellow fan of Algol 68 In the previous article in...
Using a Live USB for Linux recovery
Over the years I've managed to need recovery mode quite a few times. Most of those instances were self-inflicted and...
Getting Started with SELinux
SELinux was developed by the NSA to provide a highly secure computing environment. True to the GPL, they have made this code available to the rest of the Linux community and it is included as part of nearly every mainstream distribution.
A Small Algol 68 Project, Part 2
In memory of J. Kevin Douglas, a good friend and fellow fan of Algol 68 In the last article in...
About those livesys error messages
Do you see error messages about livesys and livesys-late on the console and in the systemd journal like those in...
A Small Algol 68 Project, Part 1
In memory of J. Kevin Douglas, a good friend and fellow fan of Algol 68 In the last article in...