Sponsored Content
Top Forums Shell Programming and Scripting Would like to see how others would do this... Post 302119893 by Shell_Life on Friday 1st of June 2007 11:29:44 AM
Old 06-01-2007
Praveen,
Coincidently, my solution is very similar to yours.
The issue that I see in your solution is the fact that you are loading
the entire file into one string.
This can cause problems in the performance for large files.
Here is my solution not loading the entire file into a string:
Code:
typeset -i mPctLimit=50
typeset -i mTimeLimit=3

mInpFile='b'
mTimeRE='[0-9][0-9]:[0-9][0-9]:[0-9][0-9]'
mHHRE='[0-9][0-9]'
mMMSSRE='[0-9][0-9]:[0-9][0-9]'

mPerctLine=`sed -n '/.*%.*/p' ${mInpFile}`
mPerctValue=`echo ${mPerctLine} | sed 's/.*(\([0-9].*\)%).*/\1/'`
echo "mPerct = "$mPerctValue" limit = "${mPctLimit}
if [ ${mPerctValue} -gt ${mPctLimit} ];then
 echo "Above the percentage limit"
fi

mHoursLine=`sed -n "/.*${mTimeRE}.*/p" ${mInpFile}`
mHoursValue=`echo ${mHoursLine} | sed "s/.*\(${mHHRE}\):${mMMSSRE}.*/\1/"`
echo "mHours = "$mHoursValue" limit = "${mTimeLimit}
if [ ${mHoursValue} -gt ${mTimeLimit} ];then
 echo "Above the time limit"
fi

 
utmpset(8)						      System Manager's Manual							utmpset(8)

NAME
utmpset - logout a line from utmp and wtmp file SYNOPSIS
utmpset [ -w ] line DESCRIPTION
The utmpset program modifies the user accounting database utmp(5) and optionally wtmp(5) to indicate that the user on the terminal line has logged out. Ordinary init(8) processes handle utmp file records for local login accounting. The runit(8) program doesn't include code to update the utmp file, the getty(8) processes are handled the same as all other services. To enable local login accounting, add utmpset to the getty(8) finish scripts, e.g.: $ cat /service/getty-5/finish #!/bin/sh exec utmpset -w tty5 $ OPTIONS
-w wtmp. Additionally to the utmp file, write an empty record for line to the wtmp file. EXIT CODES
utmpset returns 111 on error, 1 on wrong usage, 0 in all other cases. SEE ALSO
sv(8), runsv(8), runit(8), runit-init(8) runsvdir(8), runsvchdir(8), chpst(8), svlogd(8), getty(8) http://smarden.org/runit/ AUTHOR
Gerrit Pape <pape@smarden.org> utmpset(8)
All times are GMT -4. The time now is 10:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy