You are not logged in.
Is there a way to get the last shutdown time in a numerical format (e.g. seconds since the epoch, yyyy-mm-dd hh:mm:ss) from within a script?
last -x | grep shutdown | head -1
contains abbreviations for the month and doesn't list the year (although I can get that with "last -x | tail -1"). Although it's not that difficult to get a standard numerical format using some regexes, I want something that is locale-independent and simpler.
Also, I'm asking because I'm considering writing a script that could run cronjobs that would have been run since the last shutdown on systems that aren't always up. I'm aware of anacron but it isn't able to automatically check which cronjobs would have been run (correct me if I'm wrong). Is there already some simple way or some other app that can do this? As an example, if there is a weekly job that would normally run at midnight on Sunday and it gets missed, I want it to be run the next time the computer is started.
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
It sounds like you're writing a daemon anyway, so why not just record the time the daemon is stopped when the computer shuts down?
Dusty
Offline
...because I hadn't thought that far ahead yet? I'd only been thinking along the lines of some script that would get run right after booting.
To store the time at shutdown, I could just add the following line to /etc/rc.local.shutdown, right?
date +"%F %T" >/path/to/file
That's good enough for me anyway. Thanks, Dusty.
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline