The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
is there a way to find out the tty from which the process is launched sleepy_11 UNIX for Advanced & Expert Users 1 04-07-2008 02:08 AM
Find CPU per process in AIX yamsin789 Shell Programming and Scripting 0 10-31-2007 12:23 AM
How to find which process is using up too much CPU 0ktalmagik SUN Solaris 1 06-03-2006 12:48 AM
how to find the chid process id from given parent process id guhas Shell Programming and Scripting 3 10-13-2005 05:13 AM
find eof, then process mfilby Shell Programming and Scripting 12 12-22-2003 03:29 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #8  
Old 05-19-2006
MizzGail's Avatar
Registered User
 

Join Date: Sep 2001
Location: Syracuse, NY
Posts: 158
back into this again

I'm back into this issue again.
What I want to do:
I need to identify processes that have reverted to PPID 1 for a specific user.
I need to kill all the processes that are over 2 hours old that have reverted to PPID 1.

I have used the grep command and stored the processes in a file.

I can identify processes over a day old by looking for the Month in the date field.

I'm having a problem getting the hour logic to work.
Can anyone help me on this?

currHR=`date +%H`
echo $currHR
LastHr=`expr $currHR - 1`
echo $LastHr
#
cat $TMP2 | while read b
do
ProcessTime=`echo $b | awk '{print $5}'`
ProcessHour=`echo $ProcessTime | awk -F: '{print $1}'`
Killid=`echo $b | awk '{print $2}'`
echo "ProcessTime " $ProcessTime
echo "ProcessHour " $ProcessHour
case $ProcessTime in
M*|J*|F*|A*|S*|O*|N*|D* ) echo $ProcessTime "Day old " ;;
* ) case $ProcessHour in
$currHR) echo "current hour " ;;
$LastHr) echo "last hour ";;
esac
echo $ProcessTime "other " ;;
esac
done

The logic recognizes currHR as 08 (etc)
The logic recognizes LastHr as 7 (etc)
The logic recognizes ProcessHour as 07, 08 (etc)
The 2nd case logic for processhour does not match current or last hour.
Reply With Quote
Forum Sponsor
  #9  
Old 05-24-2006
Registered User
 

Join Date: Mar 2006
Location: South Yorkshire, UK
Posts: 114
To make the tests work you need to make sure you compare like with like, strings like 08 and 8 are different - even tho they have the same numeric values. You could define your variables to ensure the strings are in the same format (using "typeset -Z2" <varname>) or use integers (typeset -i <varname>).
You might also want to be able to cope with the last hour going negative (between midnight and 1 minute to 1am).

However, if you want to find the process for the current hour (i.e. the last 60 minutes) and the previous hour (60 to 120 minutes ago) then you need to take the minutes into account.

Suggestions:
Code:
typeset -Z2 currHR=`date +%H`
echo Current hour is $currHR
typeset -Z2 currMI=`date +%M`
echo Current min is $currMI
typeset -Z2 lastHR=`expr $currHR - 1`
echo Last hour is $lastHR
if [ $lastHR -lt 0 ]; then
  lastHr=23
fi
typeset -Z2 prevHR=`expr $lastHR - 1`
echo Prev hour is $prevHR
if [ $prevHR -lt 0 ]; then
  prevHr=23
fi

cat $TMP2 | while read b
do
print "\n$b"
  processTime=`echo $b | awk '{print $5}'`
  processHR=`echo $processTime | awk -F: '{print $1}'`
  processMI=`echo $processTime | awk -F: '{print $2}'`
  killid=`echo $b | awk '{print $2}'`
  echo "Process time " $processTime
  echo "Process hour " $processHR
  echo "Process min  " $processMI

  if [ "$processMI" = "" ];  then
    echo "Day old "
  elif [ $processHR = $currHR ]||([ $processHR = $lastHR ]&&[ $processMI -ge $currMI ]); then
    echo "current hour "
  elif [ $processHR = $lastHR ]||([ $processHR = $prevHR ]&&[ $processMI -ge $currMI ]); then
    echo "last hour "
  else
    echo "other "
  fi
done
I've also taken the liberty of changing your variable names to make them follow a single standard - it gets hard to maintain code where UPPER/lower case and descriptive parts are not consistent (e.g. "hours" variables were sometimes HR, sometimes Hr and sometimes Hour). Apologies for pickiness

hope this helps
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0