I’m trying to build a bash script that automatically do upgrades to the distro via the cron tab every month or two. When I manually run the script it goes through everything fine and reboots at the end and it seems to go through all the available upgrades (listed manually in a separate file) but at the end it gets stuck in an infinite reboot loop. Has anyone else written something like this?
Here is what the script does:
step 1) initialize a few variables to check the version of the PBX, check the newest available version, and some possibly extraneous stuff like checking the runlevel (for which rcX.d folder to put a S(tart) or K(ill) script in).
step 2) if the version is the same as the newest available version remove the lines I add to rc.local at the end of the script or rcX.d as well as this script and the version list and then exit the script. If it’s not the newest version then either add start script to rc${runlevel}.d OR add the /upgradescript line to rc.local (I’ve tried it both ways, I comment one or the other out of the script so I’m not changing both at the same time).
step 3) check for /upgradescripts as suggested in the upgrade wiki page. Not necessary admittedly.
step 4) check to make sure the line is in the crontab and if not add it.
step 5) get the version name for the next one on the list and do the wget, chmod, and ./ commands. I had a problem with my script moving on before the downloaded upgrade script from Schmooze finished upgrading so I added && and some menial task (&& echo “done upgrading, moving on”) to make it wait for the other script to finish. That works, at least the first time through.
step 6) check again if we’re on the newest version. If yes remove files and remove lines from rc.local, sleep for 1s to make sure it finishes removing the files and lines, and then shutdown -r 15 “the script thinks we ARE at the newest level”. If not at the current level it does shutdown -r 15 “we are NOT at the newest level, make sure this should be restarting. ctrl C to cancel shutdown”. I added the text so I can see which shutdown command was being triggered.
I’m not sure what all is happening since watching the console doesn’t show me much. It shuts down and I see that white line moving across the screen. As soon as it gets all the way across I see a brief glimpse of the upgrade routine going through all the steps and then it shuts down again. Since I don’t have time to get my ssh session to reload I’ve been leaving a tab open in my internet browser and refreshing the admin/config.php?display=sysadmin page and can watch the version number ticking upwards but once it gets to the last item on the list it just keeps rebooting without a good way to stop it.
Other relevant info:
-I’m testing this on virtual machines that I can quickly recreate when I break them.
-I’ve tested on both the 32 and 64 bit versions.
-So far I’ve only tested starting with distro levels in the 5.211.65 track
-I’ve tested separately each of the steps in my script and they seem to do their job. Just not sure what’s causing this reboot loop.
Any insight is appreciated, thanks.