[olug] Uptime to boot date --(simple method)

VincentR vincentr at cox.net
Wed Oct 30 22:36:21 UTC 2002


Here some more snippets along the same lines:

Find out how log a process has been running:
---------------------------------------------------------------------------
for p in `pidof $your_job`; do
   SYS_START=`cat /proc/uptime | cut -d\  -f1 | cut -d. -f1`
   PROC_START=`cat /proc/$p/stat | cut -d\  -f22`
   PROC_START=$(( $PROC_START / 100 ))
   PROC_UPTIME=$(( $SYS_START - $PROC_START ))
   PROC_START=`date -d "-${PROC_UPTIME} seconds"`
   echo "*** $your_job process $p has been running since: $PROC_START"
done
---------------------------------------------------------------------------

Get uptime info using procfs:
---------------------------------------------------------------------------
HOST=`hostname | awk -F. '{print $1}'`
UPSECS=`cat /proc/uptime | awk -F. '{print $1}'`
UPHOURS=$(( $UPSECS / 60 / 60 ))
UPDAYS=$(( $UPSECS / 60 / 60 / 24 ))
   if [ $UPHOURS -le 72 ]; then
      echo "$HOST has been up for $UPHOURS hours"
   else
      echo "$HOST has been up for $UPDAYS days"
---------------------------------------------------------------------------
----- Original Message -----
From: "VincentR" <vincentr at cox.net>
To: <olug at olug.org>
Sent: Wednesday, October 30, 2002 4:21 PM
Subject: Re: [olug] Uptime to boot date --(simple method)


> Here's the easiest way I know:
> One simple line  :)
>
> date -d "-`cat /proc/uptime | cut -d\  -f1 | cut -d. -f1` seconds"
>
>
> ----- Original Message -----
> From: "Jon H. Larsen" <relayer at omahadirect.net>
> To: <olug at olug.org>
> Sent: Tuesday, October 29, 2002 11:27 AM
> Subject: [olug] Uptime to boot date
>
>
> >
> >
> > Anyone know a quick way how I can turn the uptime output into an actual
> > date/time of the last boot?  Would it be the date command?
> >
> > [~]$ uptime
> >  11:25am  up 493 days,  2:41
> >
> > Jon L.
> >
> > --
> >  [ Jon H. Larsen  - email: relayer at omahadirect dot net         ]
> >  [ ICQ#: 10412618 - http://www.animesunday.org/jonl               ]
> >  [ PGP Pubkey - http://www.animesunday.org/jonl/relayerpubkey.txt ]
> >
> > _______________________________________________
> > OLUG mailing list
> > OLUG at olug.org
> > http://lists.olug.org/mailman/listinfo/olug
>
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug




More information about the OLUG mailing list