You are not logged in.

#1 2008-10-26 18:43:11

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

getting the last shutdown time numerical format

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 StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#2 2008-10-26 19:13:06

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: getting the last shutdown time numerical format

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

#3 2008-10-26 19:29:26

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: getting the last shutdown time numerical format

...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 StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB