Operating System - HP-UX
1753809 Members
7702 Online
108805 Solutions
New Discussion

Re: how to use lsof to find files

 
Dennis Handly
Acclaimed Contributor

Re: how to use lsof to find files

>Would  it be possible to have  help on a script that would kill all the output of the lsof command?

 

This will select the PIDs:

UNIX95=EXTENDED_PS ps -H -f -p $(lsof +aL1 /var | awk '
BEGIN {
   Large_file = 1000000 # min size to flag
   Regular_file = "REG"
   pid_list = ""
   getline # eat header
}
$8 == 0 && $5 == Regular_file && $7 >= Large_file {
   if (pid_list == "")
      pid_list = $2
   else
      pid_list = pid_list "," $2
}
END {
   print pid_list
}')

 

Kill them:

kill $(lsof +aL1 /var | awk '
BEGIN {
   large_file = 1000000 # min size to flag
   regular_file = "REG"
   pid_list = ""
   getline # eat header
}
$8 == 0 && $5 == regular_file && $7 >= large_file {
   if (pid_list == "")
      pid_list = $2
   else
      pid_list = pid_list " " $2
}
END {
   print pid_list
}')

NDO
Super Advisor

Re: how to use lsof to find files

Thank you , as you said "dangerous", I am a bit reluctant.

NDO
Super Advisor

Re: how to use lsof to find files

all the processes seen by "ps" are the same script (crontab entry)

mcelrate[390]/ #UNIX95=EXTENDED_PS ps -H -f -p 7121,7122,7127,7142
ps: error on write
ps: error on write
UID        PID  PPID  C    STIME TTY          TIME CMD
ora10g    7142 11688  0  Sep 13  ?           25:44 /usr/bin/sh /data8/oradata/files/rms/cronFTP_1830.ksh
ora10g    7122 21593  0  Sep 13  ?           25:42 /usr/bin/sh /data8/oradata/files/rms/cronFTP_1830.ksh
ora10g    7121     1  0  Sep 27  ?           00:00 sh -c /data8/oradata/files/rms/cronFTP_1830.ksh
ora10g    7127  7121  0  Sep 27  ?           00:00   /usr/bin/sh /data8/oradata/files/rms/cronFTP_1830.ksh

 

Dennis Handly
Acclaimed Contributor

Re: how to use lsof to find files

>as you said "dangerous", I am a bit reluctant.

 

Dangerous in that if you don't review the output from the first, you might kill too many with the second.

You could put a check on the USER column.

 

>all the processes seen by "ps" are the same script (crontab entry)

 

These are all old.  One tree has been orphaned.

Can you add these PIDs to the list to run under ps: 11688 21593