Krrishv
December 20, 2006, 5:04am
1
Matez,
I have a list of process id's in a text file. I want to know how to find the idle time of a process which are more than 300secs and kill them accordingly.
Could you please help me to get these details. I want to write a shell script with this.
Thanks..Krish
vino
December 20, 2006, 5:16am
2
See the script in check the process
Krrishv
December 20, 2006, 5:17am
3
Matez,
I have a list of process id's in a text file. I want to know how to find the idle time of a process which are more than 300secs and kill them accordingly.
Could you please help me to get these details. I want to write a shell script with this.
Thanks..Krish
Krrishv
December 20, 2006, 5:26am
4
Vino,
Thank you very much for your help man...could you please explain me the below..
W=$(which w)
PS=$(which ps)
SED=$(which sed)
AWK=$(which awk)
TTY=$($PS -o tty4 $PID)
TTNo=$(echo "$TTY" | $SED -e '/TTY/d')
TIME=$($W | $SED -n -e "/pts\/$TTNo/p" | $AWK '{ print $5 }')
thanks..krish
Krrishv
December 20, 2006, 5:38am
5
when i executing i get the below error. mine is a HP UX box.
crypto $ ./process.sh 4722
/bin/ps: illegal option -- o
usage: /bin/ps [-edaxzflP] [-u ulist] [-g glist] [-p plist] [-t tlist] [-R prmgroup] [-Z psetidlist]
4722 has been idle for -n
./process.sh[28]: -n: bad number
vino
December 20, 2006, 5:39am
6
Please dont duplicate your posts. Merging the other thread.
Krrishv
December 20, 2006, 5:42am
7
am sorry will delete that..can you help me with this..
vino
December 20, 2006, 5:44am
8
krrishv:
when i executing i get the below error. mine is a HP UX box.
crypto $ ./process.sh 4722
/bin/ps: illegal option -- o
usage: /bin/ps [-edaxzflP] [-u ulist] [-g glist] [-p plist] [-t tlist] [-R prmgroup] [-Z psetidlist]
4722 has been idle for -n
./process.sh[28]: -n: bad number
I dont have an HP UX box with me to crosscheck. See if you have any other ps version's installed on your box. And see if it has the -o flag supported.
Krrishv
December 20, 2006, 5:47am
9
Nope it doesn't support -o option..nyother way...
aju_kup
December 20, 2006, 5:48am
10
TTY=$($PS -o tty4 -o $PID)
Krrishv
December 20, 2006, 5:49am
11
could you please let me know what does the -o option does there so that i can find any equallant option available in HP-Ux
Krrishv
December 20, 2006, 5:50am
12
aju thnx for your post actually -o option is not there in HP-UX at all...
Krrishv
December 20, 2006, 5:56am
13
i think i have to use this is that right..
The controlling terminal for the process. The
tty : default heading for this column is TT if -o is
specified and TTY otherwise.
Krrishv
December 20, 2006, 6:00am
14
i got it buddies thnx....it shoud be like this
TTY=$($PS tty4 -o $PID)
no -o after ps and now if i execute the script it says like this.
crypto $ ./process.sh 4722
sed: /pts\/ 4560 pts/0 0:00 bksm is not a recognized function.
4722 has been idle for
could u pls check vino.
Krrishv
December 20, 2006, 6:06am
15
here s the complete output of the script.
crypto $ sh -x process.sh 4722
+ set -o vi
+ alias h=history 23
+ alias rm=rm -i
+ alias cp=cp -i
+ alias mv=mv -i
+ alias l=ls -m
+ alias ll=ls -l
+ alias lsf=ls -F
+ [[ -z 4722 ]]
+ [[ 4722 != +([0-9]) ]]
+ PID=4722
+ + which w
W=/bin/w
+ + which ps
PS=/bin/ps
+ + which sed
SED=/bin/sed
+ + which awk
AWK=/bin/awk
+ + /bin/ps tty4 -o 4722
TTY= PID TTY TIME COMMAND
7016 pts/0 0:00 ps
4560 pts/0 0:00 bksm
4570 pts/0 0:00 ksh
7007 pts/0 0:00 sh
+ + /bin/sed -e /TTY/d
+ echo PID TTY TIME COMMAND
7016 pts/0 0:00 ps
4560 pts/0 0:00 bksm
4570 pts/0 0:00 ksh
7007 pts/0 0:00 sh
TTNo= 7016 pts/0 0:00 ps
4560 pts/0 0:00 bksm
4570 pts/0 0:00 ksh
7007 pts/0 0:00 sh
+ + /bin/w
+ /bin/awk { print $5 }
+ /bin/sed -n -e /pts\/ 7016 pts/0 0:00 ps
4560 pts/0 0:00 bksm
4570 pts/0 0:00 ksh
7007 pts/0 0:00 sh/p
sed: /pts\/ 7016 pts/0 0:00 ps is not a recognized function.
TIME=
+ echo 4722 has been idle for
4722 has been idle for
+ [[ = *day* ]]
+ IDLE=
+ [[ -gt 30 ]]
[1] + Done sh kri1.sh&
Actually, yes it is. Read the man page . And see this thread .
Krrishv
December 20, 2006, 7:46am
17
Thatz fine...i fixed that one already reading the man page...as per man page if -o is specified it should be tty else tt am i right
TT=$($PS -o tty4 $PID)
but itz giving a error ps is not a function i dunno why..can u help in that...am not tht much familiar with shell scripts..just started writing guyz..so please help me guru's..thnx..
Krrishv
December 20, 2006, 8:27am
18
can smebody help 2 me..on this...cmon guru's plz help this poor chap..
aju_kup
December 20, 2006, 8:38am
19
chk your sed command, in this u forgot to put / at end
sysgate
December 20, 2006, 8:38am
20
why don't you hire a UNIX admin, and stop double-posting, using "cyber-chat" phrases ?