Processes

I have a file like this.

No. State Query Times User Processed Syslog
1 ready idle 973s 0 /Application/ugsvols/bldata01/logs/imanscript1562.syslog
2 ready idle 803s 83997 13 /Application/ugsvols/bldata01/logs/imanscript1542.syslog
3 ready idle 2954s 106641 5 /Application/ugsvols/bldata01/logs/imanscript24717.syslog
4 ready idle 5674s 82692 15 /Application/ugsvols/bldata01/logs/imanscript16618.syslog
5 ready idle 12626s X035077 5 /Application/ugsvols/bldata01/logs/imanscript27216.syslog
6 ready idle 16088s X038493 19 /Application/ugsvols/bldata01/logs/imanscript16795.syslog
7 ready idle 19069s 105837 14 /Application/ugsvols/bldata01/logs/imanscript8563.syslog

the final number before .syslog is the process id.

for eg: in the above if you take 7th one 8563 is the PID.

Now what i want to achieve is if the user name is null in the users column all
the process should be killed. then it should check for all users. if the users idle time that is $4 is greater than 20000 secs it should kill those process. Please let me know how to acheive this.

i tried the below command for $4 > 200000s but it's not printing correctly.

cat procs.txt|awk '{if( $4 > 200000s ) print $4,$7 }

awk ' { tm=$4; sub("s","",tm); if( tm > 20000 ) print } ' file

Anbu, it's showing me all the values not above 200000

crypto $ awk ' { tm=$4; sub("s","",tm); if( tm > 200000 ) print } ' procs.txt
1 ready idle 417s 0 /Application/ugsvols/bldata01/logs/imanscript1562.syslog
2 ready idle 247s 83997 13 /Application/ugsvols/bldata01/logs/imanscript1542.syslog
3 ready idle 2398s 106641 5 /Application/ugsvols/bldata01/logs/imanscript24717.syslog
4 ready idle 5118s 82692 15 /Application/ugsvols/bldata01/logs/imanscript16618.syslog
17 ready idle 81948s 1 /Application/ugsvols/bldata01/logs/imanscript27577.syslog
18 ready idle 86150s 1 /Application/ugsvols/bldata01/logs/imanscript15930.syslog
19 ready idle 99052s 1 /Application/ugsvols/bldata01/logs/imanscript8456.syslog
23 ready idle 241869s 1 /Application/ugsvols/bldata01/logs/imanscript7477.syslog
24 ready idle 400285s 1 /Application/ugsvols/bldata01/logs/imanscript5391.syslog
25 ready idle 491500s 1 /Application/ugsvols/bldata01/logs/imanscript26470.syslog
26 ready idle 496002s 1 /Application/ugsvols/bldata01/logs/imanscript12089.syslog
27 ready idle 573108s 1 /Application/ugsvols/bldata01/logs/imanscript18055.syslog
28 ready idle 598407s 1 /Application/ugsvols/bldata01/logs/imanscript26278.syslog
29 ready idle 597933s 3 /Application/ugsvols/bldata01/logs/imanscript9307.syslog
30 ready idle 685638s 1 /Application/ugsvols/bldata01/logs/imanscript28481.syslog
31 ready idle 691340s 1 /Application/ugsvols/bldata01/logs/imanscript8238.syslog
32 ready idle 584211s 3 /Application/ugsvols/bldata01/logs/imanscript8233.syslog
33 ready idle 728545s 1 /Application/ugsvols/bldata01/logs/imanscript22388.syslog
34 ready idle 755560s 1 /Application/ugsvols/bldata01/logs/imanscript22292.syslog
35 ready idle 756461s 1 /Application/ugsvols/bldata01/logs/imanscript19214.syslog

Your first line of the file causes the problem

No. State Query Times User Processed Syslog
awk ' NR > 1  { tm=$4; sub("s","",tm); if( tm > 200000 ) print } 'procs.txt

If you are sure that only the user field contains null then try this

awk ' NF < 7 ' file

or you try this

awk ' $0 !~ "[0-9]+s [^ ]+ [0-9]+" ' file

Its working for me.

2nd one is also not working the same output.

crypto $ awk ' $0 !~ "[0-9]+s [^ ]+ [0-9]+" ' procs.txt
1 ready idle 417s 0 /Application/ugsvols/bldata01/logs/imanscript1562.syslog
2 ready idle 247s 83997 13 /Application/ugsvols/bldata01/logs/imanscript1542.syslog
3 ready idle 2398s 106641 5 /Application/ugsvols/bldata01/logs/imanscript24717.syslog
4 ready idle 5118s 82692 15 /Application/ugsvols/bldata01/logs/imanscript16618.syslog
5 ready idle 12070s X035077 5 /Application/ugsvols/bldata01/logs/imanscript27216.syslog
6 ready idle 15532s X038493 19 /Application/ugsvols/bldata01/logs/imanscript16795.syslog
7 ready idle 18513s 105837 14 /Application/ugsvols/bldata01/logs/imanscript8563.syslog
17 ready idle 81948s 1 /Application/ugsvols/bldata01/logs/imanscript27577.syslog
18 ready idle 86150s 1 /Application/ugsvols/bldata01/logs/imanscript15930.syslog
19 ready idle 99052s 1 /Application/ugsvols/bldata01/logs/imanscript8456.syslog
20 ready idle 165093s 1 /Application/ugsvols/bldata01/logs/imanscript339.syslog
21 ready idle 172267s 1 /Application/ugsvols/bldata01/logs/imanscript10643.syslog
22 ready idle 180370s 1 /Application/ugsvols/bldata01/logs/imanscript18219.syslog
23 ready idle 241869s 1 /Application/ugsvols/bldata01/logs/imanscript7477.syslog
24 ready idle 400285s 1 /Application/ugsvols/bldata01/logs/imanscript5391.syslog
25 ready idle 491500s 1 /Application/ugsvols/bldata01/logs/imanscript26470.syslog
26 ready idle 496002s 1 /Application/ugsvols/bldata01/logs/imanscript12089.syslog
27 ready idle 573108s 1 /Application/ugsvols/bldata01/logs/imanscript18055.syslog
28 ready idle 598407s 1 /Application/ugsvols/bldata01/logs/imanscript26278.syslog
29 ready idle 597933s 3 /Application/ugsvols/bldata01/logs/imanscript9307.syslog
30 ready idle 685638s 1 /Application/ugsvols/bldata01/logs/imanscript28481.syslog
31 ready idle 691340s 1 /Application/ugsvols/bldata01/logs/imanscript8238.syslog
32 ready idle 584211s 3 /Application/ugsvols/bldata01/logs/imanscript8233.syslog
33 ready idle 728545s 1 /Application/ugsvols/bldata01/logs/imanscript22388.syslog
34 ready idle 755560s 1 /Application/ugsvols/bldata01/logs/imanscript22292.syslog
35 ready idle 756461s 1 /Application/ugsvols/bldata01/logs/imanscript19214.syslog
36 ready idle 1039675s 1 /Application/ugsvols/bldata01/logs/imanscript10754.syslog
37 ready idle 1116783s 1 /Application/ugsvols/bldata01/logs/imanscript2294.syslog
38 ready idle 1121585s 1 /Application/ugsvols/bldata01/logs/imanscript16838.syslog
39 ready idle 1191791s 1 /Application/ugsvols/bldata01/logs/imanscript4748.syslog
crypto $

otherwise if i print $5 in my file it shows below like this.

crypto $ awk '{print$5}' procs.txt
0
83997
106641
82692
X035077
X038493
105837
1
1
1
1
1
1
1
1
1
1
1
1
3
1
1
3
1
1
1
1
1
1
1

as for those who doesn't have users name next column is considered as 5th column. in this situation.so can we print the single digit rows which is considered to be no users.

And first one no luck its not printing.

I made modification in the above code. Its NF < 7 and not < 6
Both the code works for me

Anbu i got the list of processes in the below format.

5293
8563
12063

now how can i insert this process id's in kill -9 command.

Anbu,

Your second one is working perfect. But i need some help for 1st one that is if the $4 > 200000. it's not working for me.
Is there any other way we can check. using sed or something

$cat temp
5293
8563
12063
$kill -9 $(<temp)

thanks anbu i got that is there any options for the 1st one. more than 200000s using sed.

because i paste your same awk command but its not working

while read a b c d e
do
  if [ ${d%s} -ge 20000 ]; then
    echo $a $b $c $d $e
  fi
done<file

yep its working fine. thank you very much anbu for your time.

Can you show your script?

Anbu, Its working fine. I also got the output only process id's but how do i set it to variable and kill it. if i say a variable and save the echo $a $b $c $d things

only first output is stored not the other outputs. how do i store them and kill

sed "s;.*/[^0-9]*\([0-9]*\)\.syslog;\1;" file

Send all the process ids to a temp file and kill process ids like

kill -9 $(<temp)

Thanks anbu its working fine.