lsof : one of the most powerfull Unix commands nobody uses

Here's a nifty overview of lsof, one of the Swiss army knives of Unix. The article mentions lsof as a command nobody uses, but that's plain wrong : I use lsof quite frequently, though some of the lsof outputs can be obtained through other programs too.

Sheena Mathew Mon, 07/09/2007 - 17:49

Hi,

We have a unix script (S1) sponning another one (S2) which in turn spons another(S3). The log is being
directed in S1 itself. And S3 also writes the errors ino the logs. Now, I want to know the name of the log
file when I am in S3. we tried using the lsof command ( filename=`lsof -p $$ -a -d 2 -Fn -O -n -l -S2 | awk
'{ if(substr($0,1,1) == "n") { print substr($0,2,80) } }'`.

The problem here is that the log file is on NAS system. The command returns name of the mount point and not the file name. Is there a way I can find all the files (or file descriptors) open on a mount point by a process?

It'll be of great help if you could throw some light on the same.

Thanks in Advance,
Sheena

kristof Mon, 07/09/2007 - 21:07

In reply to by Sheena Mathew

Why such a complicated scheme ? Try to use environment variables to pass the logfile name into the 3rd script. Or use Perl, which gives you better ways to handle such scripting.

Sheena Mathew Tue, 07/10/2007 - 21:14

In reply to by kristof

Hi,

Thanks for responding. The Child process is being called by a lot of programs. I agree that exporting the variable name from the parent process would be the best to do. But the problem here is, we will have to change a lot of scripts which use the same child process.. Just trying to avoid that.

Also, its so curious that unix is writing into the file and we donot seem to be having a way to find the name of the file.

Thanks,
Sheena