[clug] Bash Variables not Appearing in Cron mail

Martin Pool mbp at samba.org
Thu Oct 23 11:05:53 EST 2003

On 21 Oct 2003, Michael Manning/OPC <michael.manning at opc.com.au> wrote:

> G'day All,
> I have what I consider a quirky little one here.  I am trying to
> mail, via cron, the output from a small script.
> I have tried many different ways to generate the output from this
> script; echo straight to the console, echoed to the mail command (as
> done below) and piped in the cron job entry.
> My problem is that the only variable ever output when executed
> through cron is the "interface_name", I never get the transmit or
> receive variables. No matter what order I send them in nor how a I
> generate the output. Execute the script via bash command line and it
> works every time??
> I am at a loss - any ideas??  Thanks
> Here is a snippet of code the offending code - I am using arrays to
> populate the variables for each network interface and then echoing
> these out.

When cron runs your script, it is probably running it through /bin/sh.
This might be a link to bash, or some other Bourne shell such as dash.
Even if it is bash, invoking it as dash puts it into compatibility
mode in which some bash features are not available.  I think the
absence of those features is probably breaking your script.

Therefore, either explicitly run bash for your script, or test your
script with 

  /bin/sh myscript

to make it work with a plain bourne shell.


More information about the linux mailing list