IGEL OS Monthly Reboot Script


Just thought I would share my monthly reboot script I created. It checks uptime and then reboots after the device has been idle for an hour. Be kind this is my first bash script 😉 I push the file to the device and then create a custom application which autostarts the script.

Learn more, read the entire thread inside the IGEL Community o Slack

#!/bin/bash

# Set reboot trigger time to 1 hour idle

idletime=$((10006060*1)) # 1 hour in milliseconds

# Create the function to reboot if the device is idle

rebootidle() {

while true; do

idle=$(xprintidle)

echo $idle

if (( $idle > $idletime )); then

systemctl reboot

fi

sleep 5

done

}

# Sysuptime Variable will determine uptime in hours

# Loop until uptime is 30 days or more, then run the function which will loop until the device is idle for 1 hour and then reboot

# 720 hours = 30 days

while true; do

sysuptimes=$(awk ‘{print $1}’ /proc/uptime)

sysuptime=$(echo “$sysuptimes / 3600” | bc )

echo $sysuptime

if (( $sysuptime > 720)); then

notify-send -u critical -t 0 “Your computer has been up for 30 days. Please restart now or the computer will automatically restart after 1 hour of inactivity”

rebootidle

fi

sleep 5

done


Thank you for posting! Truly awesome!


Would this require the Enterprise Pack for the custom application to be used?

Or is that only for custom partitions?


No custom partition is required. I assign the file to a profile which has a custom application pointing to the file.


That script looks good. I had similar scripts running in the background for rebooting (and other things). I recently switched them to cron jobs, so I no longer need to rely on a script running constantly in the background.


can you please post your cron job here?


I have a couple, but the one that handles reboots is this one — this is the script that the cron job runs, of course, not the other parameters of the cron job:

#!/bin/bash

REBOOT_HOURS=168

MAXIMUM_DELAY_HOURS=2

MAXIMUM_SLEEP_SECONDS=$(($MAXIMUM_DELAY_HOURS * 3600))

UPTIME=`/usr/bin/printf %.0f $(/usr/bin/awk ‘{print $0/3600;}’ /proc/uptime)`

SLEEP_TIME=$((1 + RANDOM % $MAXIMUM_SLEEP_SECONDS))

/bin/sleep $SLEEP_TIME

if /usr/bin/pgrep -f igel_screensaver > /dev/null; then

if /bin/grep -q “System is out-of-date. Version 10.06.120 is available.” <(/bin/update-check –check-only); then

/bin/update

elif [ $UPTIME -ge $REBOOT_HOURS ]; then

/sbin/reboot

else

/sbin/get_rmsettings

fi

fi


awesome, thanks!

Continue reading and comment on the thread ‘IGEL OS Monthly Reboot Script’.  Not a member? Join Here!

Learn more, search the IGEL Knowledge Base



Ask a question or comment on the above message thread?

Join or log in to the IGEL Community to ask us anything and meet other IGEL customers, partners, and EUC enthusiasts.

Submit a question, or Join Today!


Popular Message Threads


Categories & Tags: