Scenario: HPUX server that runs client sessions is reaching capacity because users don't shut down their sessions properly.
Solution: Implement a cron script to run every 5 minutes to check the ps list for the process name, and start time and kill if running more than 24 hours.
Problem: Script doesn't work
I've pilfered the below from a Google thinking it'd just be a case of slipping the process name in and manipulating the output, but no matter what I set the time period to in the section:
it just returns all the processes running named "myprocessnamegoeshere ".
I'm wondering if it's something to do with having to alias the ps command at the start of the script to fool it into thinking it's an XPG4 version of ps... OR the time formatting is wrong and it's taking the *.*.* literally as *.*.* and outputting all processes irrespective of the time value set.
Here's what I've got so far:
Any help would be much appreciated chaps!
Cheers
Solution: Implement a cron script to run every 5 minutes to check the ps list for the process name, and start time and kill if running more than 24 hours.
Problem: Script doesn't work

Code:
DAYS=1
HOURS=0
MINUTES=0
SECONDS=0
I'm wondering if it's something to do with having to alias the ps command at the start of the script to fool it into thinking it's an XPG4 version of ps... OR the time formatting is wrong and it's taking the *.*.* literally as *.*.* and outputting all processes irrespective of the time value set.
Here's what I've got so far:
Code:
#!/bin/sh
alias ps="UNIX95= /usr/bin/ps"
first()
{
echo $1
}
second()
{
echo $2
}
third()
{
echo $3
}
ps -ef -o "pid etime comm" | while read PID ETIME COMM
do
case "$ETIME" in
*:* )
DAYS=1
HOURS=0
MINUTES=0
SECONDS=0
case "$ETIME" in
*-* )
X=`echo $ETIME | sed y/-/\ /`
DAYS=`first $X`
ETIME=`second $X`
;;
* )
;;
esac
X=`echo $ETIME | sed y/:/\ /`
case "$ETIME" in
*:*:* )
HOURS=`first $X`
MINUTES=`second $X`
SECONDS=`third $X`
;;
*:* )
MINUTES=`first $X`
SECONDS=`second $X`
;;
*)
;;
esac
HOURS=`echo $HOURS + \( $DAYS \* 24 \) | bc`
MINUTES=`echo $MINUTES + \( 60 \* $HOURS \) | bc`
SECONDS=`echo $SECONDS + \( 60 \* $MINUTES \) | bc`
if test "$SECONDS" -gt "3600"
then
echo $PID $COMM | grep myprocessnamegoeshere
fi
;;
* )
;;
esac
done
Any help would be much appreciated chaps!
Cheers
