uptime command not showing how long the system has been up

Hello folks,
uptime command not shows how long the system has been up.
I know it come from a corruption of /var/adm/utmpx file.

I've done :

cat /dev/null > /var/adm/utmpx

Now who and last commands work fine. But uptime still give me back an answer without the "up time".

In which way can I return to original uptime output (with no reboot, please) ?

Moreover, can I calculate time the system is up using vmstat -i ?
My OS - Sol10 Zone

Thanks

I'm not sure you can simply overwrite /var/adm/utmpx in this way. I had an odd problems with /etc/security/failedlogin (on AIX) a while back and had to recreate the file as follows:-

fwtmp -ic </dev/null >/etc/security/failedlogin

Unfortunately, this resets everything to blank.

The other way is to look at process zero or process one. They start with the operating system, indeed if you kill them, everything on the machine goes very quiet and the phone rings..... as I found out one day.

Robin
Liverpool/Blackburn
UK

I've done it... the issue is that I've only a day, not a year.

I've used vmstat -i, divided the interrupts clock by the indicated rate, and by 60(s)60(m)24(h) but I obtain a number of day that not coincide with init process day :-/

I'm not sure how to fix utmpx, but here is a perl script to display the boot time

#! /usr/bin/perl  -wl
$tt = `kstat -p -s boot_time | awk '{print \$2}'`;
($year, $month, $day, $hour, $minute, $second)=(localtime $tt)[5,4,3,2,1,0];
$year += 1900;
$month += 1;
printf "last boot at %4d-%02d-%02d %02d:%02d:%02d\n", $year, $month, $day, $hour, $minute, $second;
2 Likes

Wonderfull :slight_smile:
Thanks

1 Like

Hi,

Thanks for this perl script, it also helps me today to calculate exact last boot time.

Just can you pls descrivbe the logic to calcualte the last booth time in "kstat" command, for undertsnding.

But just wana know, How can in uptime the uptime days not show? can anybody help to know. Is there any max value in days after that its reset?

@vikash.rastogi (Who is not the original poster)
This thread is 3 months old.

I have noticed that the output from "uptime" has a variable format according to how long the machine has been up and whether any of the fields are a whole number (e.g. If you have been up an exact whole number of hours you don't see the minutes figure).

There is no maximum that I know of but I've not seen machines up for more than about 5 years.

Please give an example of your "uptime" and mention what Operating System you have. The "kstat" command is a Solaris command.