
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
How to get started with Linux
Many of the messages I see in the #Linux feeds on BlueSky and mastodon are Windows users lamenting the end of Support for Windows 10. Many are unable to upgrade to Win11 because their hardware won’t support it. Others are fed up with Windows in general and their efforts to force user to upgrade with suggestions like donating their old computers to purchase a new Win11 one.
How to find Open Source Software to replace your Windows software
Author's note: This article is based on Chapter 6 of my book, "Linux for Small Business Owners," with my coauthor...
Mastering Screenshots with KDE Spectacle:
Writing blog posts that share my experiences with Linux and open-source software often requires screenshots of accomplishing a task or...
Beware Fedora updates of April 28, 2024
It breaks iptables with no warning I'm rather angry right now but I promise to remain calm -- at least...
Learning to use System Settings in Fedora KDE Plasma
I have been using Fedora with the KDE Plasma desktop environment for almost three months, and overall, it’s been a...
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.