
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
The duf command
The duf command is an advanced form of the df command that uses boxes to separate the storage device types into local, fuse (User space file storage), and special devices.
Five things I like about the Cinnamon desktop
I’m not a distro-hopper; I’m a desktop-hopper. But I try many different desktops just to see what they’re like. Cinnamon boasts features usually found only in desktops with much greater resource consumption, like GNOME or KDE Plasma 6.X.
My first impressions of Fedora 42
You might be aware that I upgraded all of the Both.org systems over the last two days, moving from F41...
Fedora 42 upgrades at Both.org
Fedora 42 was released today, and I've been upgrading my systems. So far I've only done my internal systems and...
Fedora 42 has been released
It's now 21 years since Fedora Core 1 was originally released in November of 2003, and it's still maintaining its...
Five reasons for Windows users to move to Linux
Take back your power As the October deadline for dumping Windows 10 is fast approaching, many users are considering their...