You can achieve both things
- Shutdown on idle after specif period.
- Weather a user logged in or not it should shutdown.
with a simple bash script.
The script will check the idle time and if it is greater than given number it will completely shutdown the system.
You can then set this script to execute every minute or every 10 seconds (as you prefer) by the root cronjob. The root cron run whenever you have logged in or not logged in user as long as your PC is running. So this will solve your problem.
To get the current idle time in miliseconds you can install
sudo apt-get install xprintidle
I have created a simple bash script for you, that you can put to be excuted by the root cron:
if [ "$IDLE_TIME" -ge "$MAX_IDLE_TIME" ]; then
shutdown -h now
export DISPLAY=:0 is required in order xprintidle to work correctly under cron.
MAX_IDLE_TIME is the max idle time in miliseconds after that the computer will be shut down. 3 600 000 miliseconds is equal to one hour. You can change this value by your needs.
So now save this file somewhere on your filesystem (preferably not your home folder, because it may be encrypted). Give the sh file executable premissions:
chown +x file.sh
And then set root cron to execute it every minute:
sudo crontab -e
* * * * * /path/to/file.sh