![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems . |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| kill process | ust | UNIX for Advanced & Expert Users | 1 | 11-27-2007 09:06 AM |
| kill(0,-9) don't kill the process | umen | High Level Programming | 9 | 06-19-2007 03:09 AM |
| how to start a process and make it sleep for 5 mins and then kill that process | shrao | Shell Programming and Scripting | 6 | 03-27-2007 09:54 AM |
| When kill doesnt work, how to kill a process ? | VijayHegde | UNIX for Advanced & Expert Users | 3 | 05-12-2006 01:24 PM |
| Need to process files created an hour ago | negixx | Shell Programming and Scripting | 9 | 06-15-2005 10:31 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Kill a particular process if it's over an hour hold
I meant old not hold
I need to kill a process if it's over an hour old and then send an e-mail of the list that was killed.....? I need to kill ps -ef | grep stashd | grep ' older than an hour?' #! /bin/bash if test ps -ef | grep <stashd> (Is over an hour old)???? >>stashd_old.txt stashd_old=`cat stashd_old.txt` for i in $stashd_old; do kill -9 <stashd> echo "Found <process_name> older than 1 hour, and killed process name | mail -s "killed <process_name `date`" Jay fi done; etc this stashd process if it's over an hour old? Last edited by xgringo; 12-10-2007 at 01:33 PM. |
| Forum Sponsor | ||
|
|
|
|||
|
This will tell you the processes older than an hour....
Code:
#!/bin/sh
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=0
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
fi
;;
* )
;;
esac
done
|
|
|||
|
I put your script in hourold.sh and greped stashd what's teletype syntax error on line 1 mean?
user@host:/export/home/user/--> hourold.sh |grep 'stashd' syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype 21931 /opt/ft/st414/bin/agents/stashd 222 /opt/ft/st414/bin/agents/stashd syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype syntax error on line 1, teletype user@host:/export/home/user/--> |
|
|||
|
Quote:
I suggest you add a line that says Code:
echo DAYS=$DAYS, HOURS=$HOURS, MINUTES=$MINUTES, SECONDS=$SECONDS and Code:
echo $ETIME |
| Thread Tools | |
| Display Modes | |
|
|