The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > SUN Solaris
Google UNIX.COM


SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-10-2007
Registered User
 

Join Date: Dec 2006
Posts: 28
Stumble this Post!
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-10-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
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
Reply With Quote
  #3 (permalink)  
Old 12-10-2007
Registered User
 

Join Date: Dec 2006
Posts: 28
Stumble this Post!
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/-->
Reply With Quote
  #4 (permalink)  
Old 12-10-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
Quote:
Originally Posted by xgringo View Post
I put your script in hourold.sh and greped stashd what's teletype syntax error on line 1 mean?
It means that "bc" is getting rubbish. I tested this on Solaris 9.

I suggest you add a line that says

Code:
echo DAYS=$DAYS, HOURS=$HOURS, MINUTES=$MINUTES, SECONDS=$SECONDS
prior to the maths with bc.

and

Code:
echo $ETIME
after the "do".
Reply With Quote
  #5 (permalink)  
Old 12-10-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
I've just tested this on Solaris 10 and it works fine.

Have you copied and pasted exactly as I posted it?
Reply With Quote
  #6 (permalink)  
Old 12-11-2007
Registered User
 

Join Date: Dec 2006
Posts: 28
Stumble this Post!
SunOS hostname 5.8 Generic_117350-45

Yep triple checked still get the syntax messages. I'm getting the rest fine as well but it's throwing those messages in every so often?

Last edited by xgringo; 12-11-2007 at 09:05 AM.
Reply With Quote
  #7 (permalink)  
Old 12-11-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
I don't have a copy of Solaris 8 running here.

Can I suggest you debug it as I suggested?

Alternatively, post the result of

Code:
ps -ef -o "pid etime comm"
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:54 PM.


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

Content Relevant URLs by vBSEO 3.2.0