how to redirect in bash+crontab

how to redirect in bash+crontab

Oleg Goldshmidt pub at goldshmidt.org
Tue Jul 24 18:57:17 IDT 2012


On Tue, Jul 24, 2012 at 4:06 PM, Amos Shapira <amos.shapira at gmail.com>wrote:

> For the platforms which use a pipe for /dev/stderr try running fuser to
> see what else has it open. I suspect it would be something like a "mail"
> process initiated by cron.
>
> In general, /dev/stderr is not a standard, not portable and IMHO shouldn't
> be relied on.
>
> The shell does exactly what is expected - the "special case" you ask for
> is the &2 syntax and /dev/stderr is a hack to let you treat stderr as a
> regular file.
>

Well, I know of course that /dev/stderr is bash-specific and is not
(necessarily) portable to other shells. I did not care about that kind of
portability. The scripts are explicitly #!/bin/bash. In bash, redirecting
to /dev/stderr is well documented, and in fact "man bash" says

        Bash handles several filenames specially when they are used in
redirections, as described in the following table:
        <...>
              /dev/stderr
                     File descriptor 2 is duplicated.

This is, in fact, not what happens, since, as I mentioned, there is a call
to open(2) before dup2(2) and permissions are checked at that stage (">&2"
corresponds more closely to the above since it does dup2(2) directly). I
still suspect there is a bug somewhere because the process should be able
to write to its stderr even under cron (which is supposed to send whatever
was written to stderr by mail).

-- 
Oleg Goldshmidt | oleg at goldshmidt.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20120724/97203bd3/attachment.html>


More information about the Linux-il mailing list