#! /bin/sh # # tuptime-19991104 # Record and show total uptime and total boot-count # # Copyright 1999 by Studio Breeze. 1999 # Daisuke Nagano # Nov.04.1999 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # LAST_UPTIME_FILE="/usr/local/etc/tuptime/lasttotaluptime"; LAST_BOOTCOUNTS_FILE="/usr/local/etc/tuptime/lastbootcounts"; case `uname` in Linux) UPTIME_D=`cat /proc/uptime | cut -f1 -d' '`; UPTIME_H=`echo $UPTIME_D | cut -f1 -d'.'`; UPTIME_L=`echo $UPTIME_D | cut -f2 -d'.'`; ;; *) exit 1; ;; esac #MY_UPTIME=$[$UPTIME_H*100+$UPTIME_L]; MY_UPTIME=$[$UPTIME_H]; # # get last uptime # if [ -f $LAST_UPTIME_FILE ]; then LAST_UPTIME=`cat $LAST_UPTIME_FILE`; else LAST_UPTIME=0 fi UPTIME=$[$LAST_UPTIME+$MY_UPTIME]; # # get boot_counts # if [ -f $LAST_BOOTCOUNTS_FILE ]; then LAST_BOOTCOUNTS=`cat $LAST_BOOTCOUNTS_FILE`; else LAST_BOOTCOUNTS=0 fi BOOTCOUNTS=$[$LAST_BOOTCOUNTS+1]; case $1 in start) ;; stop) # # Save current time # if [ -f $LAST_BOOTCOUNTS_FILE ]; then rm -f $LAST_BOOTCOUNTS_FILE; fi echo "$BOOTCOUNTS" > $LAST_BOOTCOUNTS_FILE; if [ -f $LAST_UPTIME_FILE ]; then rm -f $LAST_UPTIME_FILE; fi echo "$UPTIME" > $LAST_UPTIME_FILE; ;; *) # # show total uptimes and boot-counts # DD=$[$UPTIME/60/60/24]; HH=$[($UPTIME/60/60)%24]; MM=$[($UPTIME/60)%60]; SS=$[($UPTIME)%60]; echo "Total boots: $BOOTCOUNTS times"; echo "Total uptime: $DD days, $HH hours, $MM minutes, $SS seconds"; echo ""; ;; esac exit 0;