thebusies
asked on
conventions of awk in a program
The lines below are an extract from a script that we run to dump users who are sitting at a system prompt for more than an hour doing nothing - Very Popular!!!
However, we are receiving complaints of people being dumped after 10 - 15 minutes regardless of activities. The author of the script is on annual holiday so I have just disabled the cron job to stop this happening. However, I decided to look at the script; .
I can inteperet the script fairly comfortably but I am a bit shy with some of the nuances in scripting. I was wondering if the statement grep "1:' could be misinterpreted as this is the only point in the script where a numerical value is compared and I wondered if it was possible that the parser(?) was only checking against the numeral 1 for a match and not 1: and consequently hitting on those who happened to be maybe just taking a comfort break
Now I am not a programmer in any language, but I do know a lot of people who are and I was curious if one of them could tell me what was happening and if my supposition was correct.
PID=`who -u | awk '{print $1 " " $2 " " $6 " " $7 " " }' | grep "1:" | | grep -v Mike | grep -v Sally | grep -v Doug | awk '{ print $4 }'`
echo $PID >>/home dir / filename
# Extra line to copy the PID number into a log file
date >> /home dir / logfile
for IDLE_USER in $PID
do
kill -9 $IDLE_USER
done
exit 0
Mike
However, we are receiving complaints of people being dumped after 10 - 15 minutes regardless of activities. The author of the script is on annual holiday so I have just disabled the cron job to stop this happening. However, I decided to look at the script; .
I can inteperet the script fairly comfortably but I am a bit shy with some of the nuances in scripting. I was wondering if the statement grep "1:' could be misinterpreted as this is the only point in the script where a numerical value is compared and I wondered if it was possible that the parser(?) was only checking against the numeral 1 for a match and not 1: and consequently hitting on those who happened to be maybe just taking a comfort break
Now I am not a programmer in any language, but I do know a lot of people who are and I was curious if one of them could tell me what was happening and if my supposition was correct.
PID=`who -u | awk '{print $1 " " $2 " " $6 " " $7 " " }' | grep "1:" | | grep -v Mike | grep -v Sally | grep -v Doug | awk '{ print $4 }'`
echo $PID >>/home dir / filename
# Extra line to copy the PID number into a log file
date >> /home dir / logfile
for IDLE_USER in $PID
do
kill -9 $IDLE_USER
done
exit 0
Mike
ASKER
As requested an output from who -u (DGUX variant of unix)
stats1:>who -u
usr1 pts/0 Aug 23 12:45 . 27406
usr2 pts/1 Aug 23 06:48 0:04 12724
usr3 pts/3 Aug 23 10:48 . 22780
usr4 pts/4 Aug 23 07:35 . 15348
Mike pts/5 Aug 23 12:47 . 27447
Mike
stats1:>who -u
usr1 pts/0 Aug 23 12:45 . 27406
usr2 pts/1 Aug 23 06:48 0:04 12724
usr3 pts/3 Aug 23 10:48 . 22780
usr4 pts/4 Aug 23 07:35 . 15348
Mike pts/5 Aug 23 12:47 . 27447
Mike
Okay from this I think we can discount what we have suspected.
`who -u | awk '{print $1 " " $2 " " $6 " " $7 " " }' would return
usr1 pts/0 . 27406
usr2 pts/1 0:04 12724
usr3 pts/3 . 22780
usr4 pts/4 . 15348
Mike pts/5 . 27447
so the login time is removed so grep 1: cannot catch it
theproblem is at some other place then
`who -u | awk '{print $1 " " $2 " " $6 " " $7 " " }' would return
usr1 pts/0 . 27406
usr2 pts/1 0:04 12724
usr3 pts/3 . 22780
usr4 pts/4 . 15348
Mike pts/5 . 27447
so the login time is removed so grep 1: cannot catch it
theproblem is at some other place then
are you sure that's the only place in the script where the users get killed ?
ASKER
yes looking at the script and my understanding off it!
ASKER
Does the scripting program need a '/' in front of the ':' in the duration column or will it recognise the 1 and the colon?
echo $PID >>/home dir / filename
I don't see anything in the script that clears down this file; Is it possible that the script is killing PIDs that were _previously_ detected as idle for a long time?
To be safe, on the line before the `exit 0`, put `>/home dir / filename`
I don't see anything in the script that clears down this file; Is it possible that the script is killing PIDs that were _previously_ detected as idle for a long time?
To be safe, on the line before the `exit 0`, put `>/home dir / filename`
I guessnot
the script is killing from the $PID variable not from the file.
or IDLE_USER in $PID
do
kill -9 $IDLE_USER
done
the script is killing from the $PID variable not from the file.
or IDLE_USER in $PID
do
kill -9 $IDLE_USER
done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
glenn
that rings a bell as we have noticed when we do a normal who, the system returns an incorrect id. I think this may be the underlying problem. I will give it a try; May take a day or two to respond as I am maxed out here at the moment
Mike
that rings a bell as we have noticed when we do a normal who, the system returns an incorrect id. I think this may be the underlying problem. I will give it a try; May take a day or two to respond as I am maxed out here at the moment
Mike
ASKER
Thanks to everyone for thier input.
Top job Glenn ta!
Top job Glenn ta!
"who -u " on your system
if one of print $1 " " $2 " " $6 " " $7 " " can contain 1: and which isn't the idle time ..
cos it might have the time of login .. which can match with 1:
so guess you have to see what are teh fileds returned by who -u , which may not be standard on all machines .. so can you just paste a few lines from the outout of
who -u
on the said system