##################################################
# Func name: stalemeter
# Depiction: Verify a running process stale or not
# Inputs : $1 - process name
# $2 - stale time in minute
# ReturnVal: The status of stale, 0 - stale, 1 - fresh
# Comment : The input stale time is limited to be in minute and ranged
# in between [1-59]. An improvement is possible henceforth.
#
# * This function is not applicable to the linux system using
# a BusyBox PS.
#
stalemeter()
{
# Format of elapse time: [[dd-]hh:]mm:ss, e.g. 02-11:54:22 (man ps)
#
elapsetime=`ps -eo etime,comm | grep $1 | /
sed 's/^[ /t]*//' | uniq -f1 | /
cut -d' ' -f1`
if [ ${#elapsetime} -gt 0 ]; then
if [ ${#elapsetime} -gt 5 ]; then
return 0; # -: more than an hour already!
else #
if [ `expr ${elapsetime:0:2}` -ge `expr $2` ]; then
return 0; # -: NOT less than threshold time input
else #
return 1; # -: less than threshold time input
fi #
fi #
else #
return 1; # -: too fresh if even absent in ps list
fi #
}
看懂sed