My server should shutdown after 01:00 am, if there was no activity in the past hour. Lets say there was the last connection at 00:43 then it should check again at 01:43.
How to write such a script/how to get last login time? Based on ssh connection
This will provide a list of users and idle times, one user per line.
Important: See the NOTES section in the man page for w. The line above produces something like this:
Then use cron to execute the script that you created to utilize the output from w. Use whichever scripting language you prefer. Perhaps you do not care about usernames, only idle times?
Any result < 3600 seconds does not meet the one-hour idle time requirement.
Doesn't that require a dynamic modification of the cron job itself? I think I might be satisfied to run it once hourly; otherwise, I would have to run the script every minute to acquire that precision.
Here is a script in PHP that works well on Linux Mint 13. It should be fine for Ubuntu or any other Linux.
Well a linux server will almost never beet the requirements to shutdown that you have stated. Linux connects to it's self constantly. That said, You could probably rig something up.
/var/log/messages will show new ssh connections.
Together you could write some kind of script to check /var/log/messages for connections in the last hour, make sure there are no active connections, and then shutdown.
This article from ibm might help.