#!/bin/ksh # $Id: up,v 1.4 2008/10/26 18:53:16 ksb Exp $ # Report the aprox time of boot, depends on datecalc (ksb) # #****p* netlint/up # NAME # up # DESCRIPTION # Netlint reports the approximate uptime of the client node. #*** #****a* up/UP_BOOT # NAME # UP_BOOT # FORMAT # UP_BOOT: date # UP_BOOT: datecalc -s "date" "offset" # DESCRIPTION # If the node has datecalc(1) installed we compute the boottime of the node. # When it doesn't we return the shell command to compute it on the reporter # host (which might not run datecalc, it might do it some other way). #*** #****a* up/UP_LIMIT # NAME # UP_LIMIT # FORMAT # UP_LIMIT: days # DESCRIPTION # If the host's OS has a maximum uptime limit it is reported here. This is # not site policy, rather the cold hard fact. # IMPACT # If a host crosses the uptime limit things might go south fast. # For example Solaris 2.6 hosts, without a major patch, fail calls to wait(3) # after 250 days. #*** PROGNAME=`basename $0 .ksh` : ${CARP:=echo} PATH=$PATH:/usr/local/bin export PATH OFF=`uptime |tr ' ' ' '| sed \ -e '/.*[up]* \([0-9][0-9]*\) day[(s ,].*/{ s//\1d/ n }' \ -e '/.*[up]* \([0-9]*[0-9]\):\([0-9]*[0-9]\)[, ].*/{ s//\1h\2m/ n }' \ -e '/.*[up]* \([0-9]*\) hr[s, ].*/{ s//\1h/ n }' \ -e '/.*[up]* \([0-9]*\) min[utes, ].*/{ s//\1m/ n }' \ -e '/.*[up]* \([0-9]*\) sec[conds, ].*/{ s//\1s/ n }' \ -e 's/.*/1d/'` if [ _-V = _$1 ] ; then echo "$PROGNAME: "'$Id: up,v 1.4 2008/10/26 18:53:16 ksb Exp $' echo "$PROGNAME: current offset \"$OFF\"" exit 0 fi # When we can't find (run) datecalc here just send the expression, the # collection/report can run it for us. RES=`TZ=GMT datecalc -s now "$OFF" 2>/dev/null` if [ -n "$RES" ] ; then $CARP UP_BOOT: $RES else $CARP UP_BOOT: datecalc -s \"`TZ=GMT date`\" \"$OFF\" fi # If there is a hard limit on uptime tell the reporter -- ksb case `uname -s` in SunOS) case `uname -r` in 5.6) # Sun 2.6 wait3 bug at 250 days $CARP UP_LIMIT: 250 ;; esac ;; esac exit 0