3 # Need to cover this also:
4 # 4:13pm up 29 day(s), 3 min(s), 3 users, load average: 1.59, 2.54, 2.58
6 uptimeOutput=`/usr/bin/uptime`;
7 PATH="/bin:/usr/bin:/usr/local/bin";
10 days=`echo $uptimeOutput | /bin/sed 's/^.* up.* \([0-9][0-9]*\) *day[\(s\)]*.*$/\1/'`;
11 if [ x"`echo $days | /bin/grep -w up`" != x ]
15 hours_mins=`echo $uptimeOutput | /bin/sed 's/^.* up [^0-9]*\([0-9][0-9]*:[0-9][0-9]*\).*/\1/'`;
16 if [ x"`echo $hours_mins | /bin/grep up`" = x ]
18 hours=`echo $hours_mins | cut -f1 -d:`;
19 minutes=`echo $hours_mins | cut -f2 -d:`;
21 hours=`echo $uptimeOutput | /bin/sed 's/^.* up.* \([0-9][0-9]*\) *hr[\(s\)]*.*$/\1/'`;
22 if [ x"`echo $hours | grep up`" != x ]
26 minutes=`echo $uptimeOutput | /bin/sed 's/^.* up.* \([0-9][0-9]*\) *min[\(s\)]*.*$/\1/'`;
27 if [ x"`echo $minutes | grep up`" != x ]
33 if [ x"`echo \"$days $hours $minutes\" | /bin/grep up`" != x ]
35 echo "Uptime UNKNOWN: Unable to parse uptime output: \"$uptimeOutput\"";
39 # 1440 minutes in a day
40 dayMinutes=`expr $days \* 1440`;
41 hourMinutes=`expr $hours \* 60`;
43 totalMinutes=`expr $dayMinutes \+ $hourMinutes`;
44 totalMinutes=`expr $totalMinutes \+ $minutes`;
46 # Has it been rebooted in the last hour?
47 if [ "$totalMinutes" -lt 60 ]
50 echo "Uptime WARNING: Uptime less than one hour (currently $totalMinutes minutes)|mins=$totalMinutes";
54 echo "Uptime OK: Currently $days days, $hours hours and $minutes minutes|mins=$totalMinutes";