Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Processor usage comparison

Status
Not open for further replies.

dwlerwill

Technical User
May 25, 2001
329
Hi All

On our Unix platform we have a problem with users sat in some form queries and leaving themselves logged in when they go home. (Which is causing a few problems on our backend database)

Me being new to scripting am having a few problems working out where to start

What we need is to take a snapshot of all users system CPU usage time

kblades 17309 17308 0 Aug 14 pts/td 4:27 ./SSMM /users/kblades/kblades.bat,e
ckirman2 14381 14380 0 10:06:27 pts/tV 0:12 ./SSMM /users/ckirman2/ckirman2.bat,e

(Top example 4:27 bottom 0:12) and them 3 hours later take another snapshot and if the times are the same email the user a warning (The email bit is already done)

Anyone know a easy way to compare the 2 times for all the users on a system and store the ones with the same CPU time in a separate log file?

Cheers all


David Lerwill
"If at first you don't succeed go to the pub"
 
I am sure there are many ways to do this, but this is how I would tackle it.
Run a script via cron every 3 hours (either 24 hours a day or just between 8am and 8pm, or whatever is appropriate).
The script, run as root, would:
Take a current snapshot of the system (ps -ef), perhaps filtered with grep '/SSMM' or grep 'pts/' to reduce the output and sort it into PID order (headings removed).
If the previous snapshot does not exist (or is too old, by some criteria) then rename the current snapshot to the previous snapshot and exit. ...
Else, read the previous snapshot, one line at a time, comparing the CPU usage time with the current snapshot, by using grep for the known PID. Bear in mind the process may have completed so may not be present in the current snapshot.
Do whatever processing is required depending on the comparison of CPU usage times, including storing the ones with the same CPU usage time in a log file.
After all lines in the previous snapshot have been checked against the current snapshot, then rename the current snapshot to the previous snapshot and exit.

I hope that helps, without actually writing the script for you.

Mike
 
How about, in pseudo code
Code:
#part 1 get list of processes

For each line in 'ps -ef'
  if line includes string 'SSMM'
     cut process_id and process_time from line and append to temp file

# Part 2 compare with previous run
if exists previous_file
  for each line in temp_file
    if process_id appears in previous_file
      if process_time same
         e-mail user 

# Part 3 swap temp and previous file

if exists previous_file 
  delete previous_file
rename temp_file previous_file

This could be run every so often as a cron job

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top