
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
Thinking about Algol 68
I took my first computer science course in my second year at the University of British Columbia in Vancouver, Canada. The course was a full year, starting in September 1974, and we programmed in Waterloo FORTRAN IV, which if memory serves was called Watfor or maybe Watfiv at the time. We also had a brief session with IBM 360 / 370 Assembler language. Both languages were available to us in the form of batch timeshare services where we wrote our programs on IBM 029 key punches and submitted the card decks to be run, generating printouts which were almost entirely compilation or execution failures interspersed with the occasional output of a program that generated the hoped-for results.
The Linux Philosophy for SysAdmins, Tenet 22—Mentor the young SysAdmins
When I first started, I was a young and innocent SysAdmin. I was fortunate because I worked at a couple different jobs where other, seasoned SysAdmins were willing to mentor me and encourage me. None of them laughed at me when I asked what must have seemed to them to have answers that were blindingly obvious. None of these patient SysAdmins ever told me to RTFM.
Do I have enough space for that?
A little scripting goes a long way to make sure you won’t run out of space with an automated process.
Strange problems with switches
Network switches are supposed to be simple devices that work at TCP/IP layer 1, the hardware layer. As far as...
Nextcloud is a snap
Recently I have been tasked with assisting a local medical office with finding a new way to store medical images...