Rebooting when Idle - troubleshooting

Zululander

New Member
Joined
Apr 24, 2024
Messages
28
Reaction score
5
Credits
248
I have tried the following but it does not appear to work.

Created the following script:
Code:
#!/bin/bash

# Get idle time in milliseconds
idle_time=$(xprintidle) #xprintidle has been installed

# Convert idle time to minutes
idle_minutes=$((idle_time / 60000))

# Check if idle time is greater than or equal to 10 minutes
if [ "$idle_minutes" -ge 10 ]; then
    shutdown -r
fi

And then added a cron job as below using "crontab -e":
Code:
* * * * * /path/to/idle-reboot.sh #path and file name of idle script

But nothing ever happens.

I am not sure if this should work and if it should, how to troubleshoot it.
 


You shouldn't have to write a script or create a cron job to reboot when your system is idle.

What os are you running?
 
Chances are VERY good that you can just use your power management tools (located in the application menu, usually in the admin section) to perform this task for you. There's no need for a cron job.
 
I have the machine logged in as a guest. I am using it like a kiosk machine. If not used for 10min, I want it to reboot. Power management does not allow this. There have been some blogs recommending my approach but it does not seem to work.... maybe the cron job resets the idle time to zero?
 
I have the machine logged in as a guest. I am using it like a kiosk machine. If not used for 10min, I want it to reboot. Power management does not allow this. There have been some blogs recommending my approach but it does not seem to work.... maybe the cron job resets the idle time to zero?
Maybe you should have the user log out after 10 minutes of inactivity instead of rebooting the whole machine.

Signed,

Matthew Campbell
 
I am building a kiosk machine for guests so want it to auto logon. But yes might be easier to log off and then remove the password so they can just click on the Guest User icon.

The reason for the reboot as I am planning on resetting the system at reboot (using overlayroot configuration)
 
I suggest you to use systemd, commands in your script as we well as cron jobs are things of the past and kept for compatibility until people switch to modern variants.

There is no reason to use deprecated methods and systems in new scripts.

There is OnUnitInactiveSec option which you could configure to trigger the timer after inactivity of some other unit.
 
I suggest you to use systemd, commands in your script as we well as cron jobs are things of the past and kept for compatibility until people switch to modern variants.

There is no reason to use deprecated methods and systems in new scripts.

There is OnUnitInactiveSec option which you could configure to trigger the timer after inactivity of some other unit.

Thanks for this. I will look at your suggestion when I get some more time.

In the meantime, just for completeness, CoPilot gave me a suggestion that seems to work for now:

Create the below script which is then called at login using startup settings in gnome-session-properties.

Code:
#!/bin/bash

# Idle time in milliseconds (10 minutes)
IDLE_TIME=$((10 * 60 * 1000))

while true; do
    idle=$(xprintidle)
    if [ "$idle" -ge "$IDLE_TIME" ]; then
        shutdown -r
    fi
    sleep 60
done
 


Members online


Latest posts

Top