|
Idle Time Tracker
Being the curious programmer, Ive been trying to bang out a script that will get the users on the system, parse out their idle time, and create a real time report that shows what their actual activity has been on that machine for that day.
Ive used several tools so far in oder to accomplish this. First I used Perl because thats my strength. This was a piece of cake. The problem is that wont ultimately do because we are using perl for development and oftentimes we do a ps -ef | grep perl looking for perl processes. I dont want my program to be seen (By the way if this is a problem that can be fixed im all ears).
Anyway, so as im not a very good shell scripter I decided I would give it a shot in bash and see what happens. I actually got pretty far, but hit a wall when I could see that in a loop, the variable scope for my awk code is reset on every iteration, it became impossible for me to keep track of how much time was passing for each record (i.e. USER).
So I decided that I would write the entire script in awk, seeing as my shell script was almost 80% Awk anyway. Im three lines in and I cant get the damned thing to execute a print statement. Can someone lend me a hand and show me what im doing wrong in either the shell script or the awk script? Thank you much in advance, I feel like my eyes are going to bleed ive been staring at the screen too long!
This wont print anything:
awk Code:
Original
- awk Code |
|
|
|
#!/bin/awk -f
{
print "Here at the top of the loop" ;
while ( "w -h" | getline )
{
print "Here is the next record", $0 ;
}
}
And here was my attempt in Bash if anyone cares to REALLY get involved.
bash Code:
Original
- bash Code |
|
|
|
#!/bin/sh while : ; do TIMENOW=1188610350 ## The problem with this design is that when the AWK portion ends, it does not retain any information about its last run. w -h | awk ' { UK = $1"|"$2; if ( ($5 ~ /s/) && (!T[UK, ST]) ) { T[UK, ST] = TIMENOW; } if ( ($5 ~ /[0-9]+[:][0-9]+[^sm]/) && (T[UK, ST]) ) { print "Field five is now into the minutes and variable ST has been set"; split($5, T, /:/) ; print "Here are the mins:",T[0],"and here are the seconds:",T[1] if (ts > MI) { T[UK, ET] = TIMENOW; TT = T[UK, ET] - T[UK, ST]; op = sprintf("%-20s %-20s %-20s %-20s", TIMENOW, $3, $1, TT); print "Done with this activity batch: ", op; T[UK, ST] = ""; T[UK, ET] = ""; } }; } ' MI=$MAXIDLE TIMENOW=$TIMENOW sleep 3 done
__________________
Bugs that go away by themselves come back by themselves
Never take life seriously, Nobody gets out alive anyway.
|