At work, I have some neat-o install scripts that generate other scripts containing configuration values.  At one point, three of these scripts output to stderr by echo’ing to /proc/self/2 (2 == stderr).  These are messages I want to be visible to the user even if they are redirecting stdout to a file.  Strangely, it works for me, but not for other people who are installing it.  They get: “/proc/self/2: Permission denied".

These “other people” are support and testing staff, and they log into Linux system using ‘personal’ IDs, then use sudo su - XXXadmin, which is what we call a ‘functional’ ID.  The directory entries at /proc/*/fd/* are owned by the first user, with permissions of (0620)

crw--w---- 1 tim  tty 136, 8 Apr  9 15:58 /proc/self/fd/2

But when the user does sudo su – XXXadmin, the ownership of /proc/self/fd/2 is still the original owner, and so XXXadmin can’t write to this ‘file’.

Long story short: I couldn’t find any bash-isms that allow echo to be redirected to file-descriptor 2 directly, so I ended up replacing the echo statement with a perl script

perl -e 'print STDERR "message\n";'

Not really happy forking an entire interpreter just to write a little message to stderr, but maybe someday I’ll stumble across a better way.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2012 LinuxTampa Suffusion theme by Sayontan Sinha