Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb Site ManagementScripts

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 31st, 2007, 10:00 PM
Matt1776's Avatar
Matt1776 Matt1776 is offline
Recovering Intellectual
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2006
Location: Orange County, CA
Posts: 989 Matt1776 User rank is Major (30000 - 40000 Reputation Level)Matt1776 User rank is Major (30000 - 40000 Reputation Level)Matt1776 User rank is Major (30000 - 40000 Reputation Level)Matt1776 User rank is Major (30000 - 40000 Reputation Level)Matt1776 User rank is Major (30000 - 40000 Reputation Level)Matt1776 User rank is Major (30000 - 40000 Reputation Level)Matt1776 User rank is Major (30000 - 40000 Reputation Level)Matt1776 User rank is Major (30000 - 40000 Reputation Level)Matt1776 User rank is Major (30000 - 40000 Reputation Level)Matt1776 User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 11 h 47 m 27 sec
Reputation Power: 370
Send a message via ICQ to Matt1776 Send a message via AIM to Matt1776 Send a message via MSN to Matt1776 Send a message via Yahoo to Matt1776 Send a message via Skype to Matt1776
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
  1. #!/bin/sh
  2.  
  3.  
  4. while : ; do
  5.  
  6.   TIMENOW=1188610350
  7.  
  8.   ## The problem with this design is that when the AWK portion ends, it does not retain any information about its last run.
  9.  
  10.   w -h | awk ' {
  11.                UK = $1"|"$2;
  12.                if ( ($5 ~ /s/) && (!T[UK, ST]) )
  13.                    {
  14.                    T[UK, ST] = TIMENOW;
  15.                    }
  16.                if ( ($5 ~ /[0-9]+[:][0-9]+[^sm]/) && (T[UK, ST]) )
  17.                    {
  18.                    print "Field five is now into the minutes and variable ST has been set";
  19.                    split($5, T, /:/) ; print "Here are the mins:",T[0],"and here are the seconds:",T[1]
  20.                    if (ts > MI)
  21.                        {
  22.                        T[UK, ET] = TIMENOW;
  23.                        TT = T[UK, ET] - T[UK, ST];
  24.                        op = sprintf("%-20s %-20s %-20s %-20s", TIMENOW, $3, $1, TT);
  25.                        print "Done with this activity batch: ", op;
  26.                        T[UK, ST] = "";
  27.                        T[UK, ET] = "";
  28.                        }
  29.                    };
  30.                } ' MI=$MAXIDLE TIMENOW=$TIMENOW
  31.  
  32. sleep 3
  33.  
  34. done
__________________
Bugs that go away by themselves come back by themselves
Never take life seriously, Nobody gets out alive anyway.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsWeb Site ManagementScripts > Idle Time Tracker


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT