Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Historic uptimes using 'last'' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Historic uptimes using 'last'
Authored by: robh on Jun 27, '01 06:21:15AM

The command 'last' will show you some recent login stats which can be used to view recent uptimes, e.g.

[prompt] last
rob console chad Thu Jun 21 22:57 still logged in
reboot ~ Thu Jun 21 22:56
shutdown ~ Thu Jun 21 22:53
rob console chad Sat Jun 9 23:57 - 22:53 (11+22:55)
reboot ~ Sat Jun 9 23:57
rob console chad Mon Jun 4 16:54 - 23:51 (5+06:56)

The figures in ()s tell me the days+hours:minutes I was logged in.

OSX keeps this info in /var/log/wtmp, but it also keeps older data backed up in /var/log/wtmp.N.gz.

Here's a little script that can be used to read all the logs and spit out just the uptimes..

#!/bin/csh

last > /tmp/$$.total

foreach f (/var/log/wtmp.?.gz)
zcat $f > /tmp/$$
last -f /tmp/$$ >> /tmp/$$.total
end

rm /tmp/$$
grep console /tmp/$$.total | grep ' - ' | sed 's/.* - //'
rm /tmp/$$.total


Save it in a file, type "chmod +x filename" to make it executable and then type "./filename | less" to run it and pipe the output into the "less" tool that displays one page of output at a time.

Here's the output of mine:

22:53 (11+22:55)
23:51 (5+06:56)
crash (1+16:59)
crash (2+20:41)
crash (4+03:35)
crash (2+22:50)
19:39 (1+01:42)
17:47 (5+22:54)
crash (1+09:16)
09:32 (8+11:01)
00:09 (2+08:39)
15:27 (00:19)
15:08 (00:07)
15:00 (00:19)
14:40 (00:01)
14:39 (00:14)
14:21 (20:04)
18:17 (8+07:03)
crash (18:10)
16:59 (17:59)
22:55 (02:49)
10:44 (21:43)
13:00 (00:02)
12:58 (3+17:35)
18:47 (00:23)
18:24 (01:29)
14:54 (00:00)
crash (1+00:29)
14:06 (00:01)
shutdown (23:40)
13:19 (2+00:42)
12:37 (2+21:51)
14:45 (00:26)
crash (00:11)
14:07 (00:32)
13:35 (12+15:21)
crash (4+00:17)
crash (2+20:40)
shutdown (1+03:04)
shutdown (7+18:49)
crash (01:07)
crash (09:07)
14:53 (00:01)
14:49 (00:03)
shutdown (00:02)
shutdown (00:01)
14:20 (10+23:10)
crash (00:36)
shutdown (04:17)
10:04 (10:01)
crash (00:08)
23:45 (00:29)
23:15 (00:41)
shutdown (00:02)


The best I've managed is 12 days of uptime.
Notice all the crashes ?. I haven't seen one for a couple of weeks now which is promising.
I found the public beta to be more stable. I could keep that one up for weeks.



[ Reply to This | # ]
Historic uptimes using 'last'
Authored by: Anonymous on Jun 30, '01 11:45:22PM

This looks like a great script, but for some reason it's not working on my machine (PB Wallstreet 233, 10.0.4)

I get a "foreach: No match." and the script dies.

Any help would be appreciated :)

-THX1138



[ Reply to This | # ]
Never mind...
Authored by: Anonymous on Jul 01, '01 02:50:55PM

I tried it again this morning, and it seems to work just fine. I think the problem was because I didn't have any "wtmp.0.gz" files in my /var/log directory. Perhaps my wtmp just got big enough to make a gzip backup of it this morning...

-THX



[ Reply to This | # ]