I need to write a script that figures out if a reboot has occurred after an RPM has been installed. It is pretty easy to get the epoch time for when the RPM was installed: rpm -q --queryformat "%{INSTALLTIME}\n" glibc | head -1
, which produces output that looks like this: 1423807455
.
This cross checks with rpm -q --info
.
# date -d@`rpm -q --queryformat "%{INSTALLTIME}\n" glibc | head -1`
Fri Feb 13 01:04:15 EST 2015
# sudo rpm -q --info glibc | grep "Install Date" | head -1
Install Date: Fri 13 Feb 2015 01:04:15 AM EST Build Host: x86-022.build.eng.bos.redhat.com
But I am getting stumped on trying to figure out how to get the epoch time from uptime
or from cat /proc/uptime
. I do not understand the output from cat /proc/uptime
which on my system looks like this: 19496864.99 18606757.86
. Why is there two values? Which should I use and why do these numbers have a decimal in them?
UPDATE: thanks techraf
here is the script that I will use ...
#!/bin/sh
now=`date +'%s'`
rpm_install_date_epoch=`rpm -q --queryformat "%{INSTALLTIME}\n" glibc | head -1`
installed_seconds_ago=`expr $now - $rpm_install_date_epoch`
uptime_epoch=`cat /proc/uptime | cut -f1 -d'.'`
if [ $installed_seconds_ago -gt $uptime_epoch ]
then
echo "no need to reboot"
else
echo "need to reboot"
fi
I'd appreciate any feedback on the script.
Thanks