1753503 Members
4765 Online
108794 Solutions
New Discussion юеВ

File Descriptors

 
Joe Kane
New Member

File Descriptors

Hi, I've got a 3rd Party scheduler which runs unix scripts on my machines. The scheduler re-directs stdout to a file on my machine. My problem is that from within the script being executed I want to find the name of the log file (which the scheduler automatically generates). I have been thinking along the line of interrogating the file descriptors, but there doesn't seem to be a way of doing this.
Thanks for any help.
8 REPLIES 8
harry d brown jr
Honored Contributor

Re: File Descriptors

Joe,

get a copy of lsof:

http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/lsof-4.61/

and use it to find your process and open files from within your script.

live free or die
harry
Live Free or Die
federico_3
Honored Contributor

Re: File Descriptors

use lsof

Ciao
Federico
Craig Rants
Honored Contributor

Re: File Descriptors

For example syslogd, the pid is 531.

server# /opt/lsof/bin/lsof -p 531
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
syslogd 531 root cwd VDIR 64,0x3 1024 2 /
syslogd 531 root txt VREG 64,0x7 36864 20338 /usr (/dev/vg00/lvol7)
syslogd 531 root mem VREG 64,0x7 40960 109 /usr/lib/libnss_files.1
syslogd 531 root mem VREG 64,0x7 20480 20348 /usr/lib/libdld.2
syslogd 531 root mem VREG 64,0x7 1552384 18166 /usr/lib/libc.2
syslogd 531 root mem VREG 64,0x7 126976 20346 /usr/lib/dld.sl
syslogd 531 root 0r VDIR 64,0x3 1024 2 /
syslogd 531 root 1r VDIR 64,0x3 1024 2 /
syslogd 531 root 2r VDIR 64,0x3 1024 2 /
syslogd 531 root 3r FIFO 64,0x3 0t2048 1246 / (/dev/vg00/lvol3) rd=0x800
syslogd 531 root 4w FIFO 64,0x3 0t2048 1246 / (/dev/vg00/lvol3) wr=0x800
syslogd 531 root 5u unix 0x30b5300 0t0 /dev/log.un
syslogd 531 root 6u inet 0x30ace40 0t0 UDP *:syslog (Idle)
syslogd 531 root 7r VCHR 189,0 0t2246 931 /dev/klog
syslogd 531 root 9w VREG 64,0x8 4009 529 /var/adm/syslog/mail.log
syslogd 531 root 10w VREG 64,0x8 44621 990 /var/adm/syslog/syslog.log
syslogd 531 root 11w VCHR 0,0 0t0 67 /dev/console

GL,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
harry d brown jr
Honored Contributor

Re: File Descriptors

Joe,

code sniplet for KSH using lsof:

WHOAMI=$$
#
# note: 0u=tty, 1u=stdout, 2u=stderr
# also tr is used to remove all extra spaces,
# TWO SPACES in first pair of quotes, then
# ONE SPACE in second pair of quotes
#
WHATisSTDTTY=`/usr/local/bin/lsof -p $WHOAMI|grep " 0u "|tr -s " " " "|cut -d"
" -f9`
WHATisSTDOUT=`/usr/local/bin/lsof -p $WHOAMI|grep " 1u "|tr -s " " " "|cut -d"
" -f9`
WHATisSTDERR=`/usr/local/bin/lsof -p $WHOAMI|grep " 2u "|tr -s " " " "|cut -d"
" -f9`


live free or die
harry
Live Free or Die
Joe Kane
New Member

Re: File Descriptors

Thanks to everyone. I had already looked at lsof, but this was not considered as it's not a core HP functional process (Company policy).
Can't think of another way.
harry d brown jr
Honored Contributor

Re: File Descriptors

Joe,

THIS is from the HP PORTING site, and is just like "perl", "emacs", "gzip/gunzip", "CIFS/9000 (samba)", "netscape browser", "apache", "JAVA", "ssh", "SSL", "vi", "awk", "sed", and about a thousand+ other things that HP doesn't write or OWN. THEY PORTED it!

My company had the same LAME policy, until I explained the ABOVE to them!

Without OPEN SOURCE, unix would be DEAD and we'd all be running M$ crap everywhere!

live free or die
harry
Live Free or Die
Steven Gillard_2
Honored Contributor

Re: File Descriptors

An alternative to lsof which may work in your case is glance. Just select the process you want to look at, then go to the open files screen and you will have a list of all files that process has open.

Not as flexible as lsof, because you have to know the pid first.

Regards,
Steve
Joe Kane
New Member

Re: File Descriptors

Thanks,
Yes indeed glance gives it. I haven't given up on lsof because it might be easier to make part of a script.
I haven't used glance much, I can't see a way of using this within a script though (I can easily get the pid), it only seems to work interactively.

The search contiues...