[lug] stderr woes

Michael Hirsch mdhirsch at gmail.com
Thu Feb 24 15:06:26 MST 2005


On Thu, 24 Feb 2005 09:02:12 -0700, Ron Wright <halsaves at gmail.com> wrote:
> ~ $ cat tmp.sh
> #!/bin/bash
> echo stderr > /dev/stderr
> echo stdout > /dev/stdout
> echo tty > /dev/tty
> ~ $ ./tmp.sh
> stderr
> stdout
> tty
> ~ $ sudo -u nobody ./tmp.sh
> ./tmp.sh: /dev/stderr: Permission denied
> ./tmp.sh: /dev/stdout: Permission denied
> tty

Try this instead:

[1000] tmp>cat ./tmp.sh
#!/bin/bash

echo stderr >&2
echo stdout >&1

echo stderr > /dev/stderr
echo stdout > /dev/stdout

[1001] tmp>./tmp.sh
stderr
stdout
stderr
stdout
[1002] tmp>sudo -u nobody ./tmp.sh
stderr
stdout
./tmp.sh: line 6: /dev/stderr: Permission denied
./tmp.sh: line 7: /dev/stdout: Permission denied

I think the problem is that /dev/stdout is a symlink that gets
interpreted at some time.  >&1 actually redirets to stdout.  Something
funny happens with the sudo causing the interpretation of /dev/stdout
to happen at the wrong time--maybe before the sudo takes place.

I can't say i understand it, but at least the workaround seems okay.

Michael

> On Thu, 24 Feb 2005 09:42:34 -0500, Michael Hirsch <mdhirsch at gmail.com> wrote:
> > On Wed, 23 Feb 2005 22:22:34 -0700, Daniel Webb <lists at danielwebb.us> wrote:
> > > I'm getting the following output sometimes from a script:
> > >
> > > /usr/local/bin/ssh-reverse-tunnel: line 63: /dev/stderr: Permission denied
> > > /usr/local/bin/ssh-reverse-tunnel: line 63: /dev/stderr: Permission denied
> > > /usr/local/bin/ssh-reverse-tunnel: line 63: /dev/stderr: Permission denied
> > > /usr/local/bin/ssh-reverse-tunnel: line 63: /dev/stderr: Permission denied
> > >
> > > Line 63 in the script is (from a function):
> > >
> > > echo "$THIS: $*" >/dev/stderr
> > >
> > > If I try:
> > >
> > > echo "test" >/dev/stderr
> > >
> > > from the command line as the same user that runs the script, it just
> > > prints "test" (to stderr, I assume).
> > >
> > > Is there some obvious thing I'm overlooking here?
> >
> > Strange.  I can't reproduce that with a silly little script.  Can you
> > create a smal script that reproduces the problem and post it?
> >
> > Michael
> > _______________________________________________
> > Web Page:  http://lug.boulder.co.us
> > Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> > Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
> >
>



More information about the LUG mailing list