I ran into a problem in a shell script. I narrowed down the problem and found that it was due to a file descriptor from standard input that is not generated in the proc file system. Below is the test script I wrote:
#!/bin/ksh var=`ls -lrt /proc/$$/path/0` echo $var if [[ -f /proc/$$/path/0 ]] then echo "found file descriptor" else echo "file descriptor not found" fi
I tested this in the / tmp / directory with an example input file:
$ ./checkip.sh < /tmp/testip lrwxrwxrwx 1 root root 0 Dec 31 09:15 /proc/19358/path/0 -> /tmp/testip found file descriptor
Now I tested in one of the directories where we ran into a problem.
$ ./checkip.sh < /var/opt/xxxxxxxx/testip lrwxrwxrwx 1 root root 0 Dec 31 09:15 /proc/20124/path/0 file descriptor not found $
I thought it was with the xxxxxxxx directory. so I checked it again with the file in the parent directory.
$ ./checkip.sh < /var/opt/testip lrwxrwxrwx 1 root root 0 Dec 31 09:16 /proc/21286/path/0 -> /var/opt/testip found file descriptor $
It worked again. But I do not see the difference between the permissions of the opt directory and xxxxxxxx
$ ls -l |grep xxxxxxxx drwxr-xr-x 292 abcdefg abc 8192 Dec 31 08:33 xxxxxxxx $ cd .. $ ls -l | grep opt drwxr-xr-x 17 abcdefg abc 512 Dec 31 09:14 opt
I am confused by why the symbolic link for 0 (standard input) is not created correctly. Can someone help me find the reason for this?
EDIT - for comment
file does not exist
$ ./checkip.sh < /tmp/notexistfile /tmp/notexistfile: No such file or directory.
file exists
$ ./checkip.sh < /var/opt/testip lrwxrwxrwx 1 root root 0 Dec 31 10:49 /proc/15917/path/0 -> /var/opt/testip found file descriptor
file exists
$ ./checkip.sh < /var/opt/xxxxxxxx/testip lrwxrwxrwx 1 root root 0 Dec 31 10:49 /proc/16566/path/0 file descriptor not found $
The problem I could see was a symlink for standard input in proc / pid / path / 0, which is not created for a single directory. But what could be the reason. I have no ideas !. Even the farm output does not show anything about how the file (sym link) proc / pid / path / 0 is created.
Truss output: working register (check if stat64 call succeeded):
9107/1: 0.0117 read(62, 0xFEF687A0, 1024) = 116 9107/1: # ! / bin / ksh\n\nif [ [ - f / proc / $ $ / p 9107/1: ath / 0 ] ]\nthen\necho " foundfiled 9107/1: escriptor "\nelse\necho " filedescr 9107/1: iptornotfound "\nfi\n 9107/1: 0.0118 sysconfig(6) = 4096 9107/1: 0.0119 stat64(0x0808E630, 0x08089B40) = 0 9107/1: 0x0808E630: "/proc/9107/path/0" 9107/1: d=0x04F40002 i=4191608033 m=0100644 l=1 u=308 g=205 sz=3 9107/1: at = Dec 31 08:33:06 GMT 2014 [ 1420014786.307569314 ] 9107/1: mt = Dec 31 08:33:06 GMT 2014 [ 1420014786.307619723 ] 9107/1: ct = Dec 31 08:33:06 GMT 2014 [ 1420014786.307619723 ] 9107/1: bsz=4096 blks=8 fs=tmpfs
farm output: the case does not work (check the failure of the stat64 call):
10125/1: 0.0057 read(62, 0xFEF687A0, 1024) = 116 10125/1: # ! / bin / ksh\n\nif [ [ - f / proc / $ $ / p 10125/1: ath / 0 ] ]\nthen\necho " foundfiled 10125/1: escriptor "\nelse\necho " filedescr 10125/1: iptornotfound "\nfi\n 10125/1: 0.0058 sysconfig(6) = 4096 10125/1: 0.0071 stat64(0x0808E630, 0x08089B40) Err#2 ENOENT 10125/1: 0x0808E630: "/proc/10125/path/0" 10125/1: 0.0071 lwp_sigmask(3, 0x00020000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF] 10125/1: 0.0071 stat64(0x0808E792, 0x08047600) Err#2 ENOENT 10125/1: 0x0808E792: "/usr/sbin/echo" 10125/1: 0.0072 lwp_sigmask(3, 0x00000000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF] 10125/1: 0.0072 lwp_sigmask(3, 0x00020000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]