[clug] Bash Variables not Appearing in Cron mail

Michael Manning/OPC michael.manning at opc.com.au
Tue Oct 21 09:31:27 EST 2003






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.

--snip--

for (( COUNT=1; $COUNT <= $NUM_INTERFACES; COUNT=$COUNT+1 )); do

........

OTHER CODE HERE TO POPULATE THE VARIABLES
............

    MAILOUT[$COUNT]="Interface ${INTERFACE_NAME[$COUNT]} -- Received Bytes are ${RECEIVE_INTERFACE[$COUNT]} -- Transmitted bytes are
${TRANSMIT_INTERFACE[$COUNT]}";


done

# Now lets mail it!!

( echo "Here are the statistics for $(date)";
     for (( COUNT=1; $COUNT <= $NUM_INTERFACES; COUNT=$COUNT+1 )); do
    echo ${MAILOUT[$COUNT]}; done) \
      | mail -s "stats from laptop" $EMAIL_ADDRESS

--snip--


Here is a sample of the cron entry that I am using also:

* * * * *   /data/michael/ifconfigMailer


                                                                                                                                                       
 Michael Manning                                                                                                                                       
                                                                                                                                                       
 Mail: michael at catman.homelinux.org                                                                                                                    
 Web: https://catman.homelinux.org                                                                                                                     
                                                                                                                                                       





More information about the linux mailing list