homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

Can't call gzip and mailx from cron

5+ Year Member

Msg#: 3761604 posted 6:31 pm on Oct 8, 2008 (gmt 0)

Hello Friends,

I am new to shell scripting and this is the first time I am trying to use cron to automate a job. The script I use generates a huge log file which I wish to mail out.

My script runs fine when called from the command line but fails to zip and mail when called from cron. Below is the script I am using



fname=`/bin/date '+active_alarms_%h%d%y_%H.xls'`

### script to generate the alarms log file goes here

#### compressing the collected report
/bin/usr/gzip $fname

#### mailing zipped collection report
TO="nanu@xyz.com "
(cat body; uuencode "$fname.gz" "$fname.zip") /bin/mailx -s "Active Alarms Collector Report" "$TO"

Please could someone tell me what I am doing wrong here? I am at my wits end as the script behaves when called from command prompt. I guess I am missing some environmental variables but which ones?



WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Msg#: 3761604 posted 11:10 pm on Oct 8, 2008 (gmt 0)

normally the output of a cron script is mailed to the owner of the cron process (root?) or the user specified in the MAILTO environment variable.
perhaps the commands sent some output you haven't seen?
if you have problems seeing the emailed output, you could try redirecting standard error and output to a file that you can examine after cron runs.

have you looked at the value of the error codes returned by the commands.
the special variable $? contains the return code of the last commmand...


5+ Year Member

Msg#: 3761604 posted 10:37 am on Oct 9, 2008 (gmt 0)

Hi phranque,

Many thanks for your reply ...
On checking the mailbox I found that gzip & mailx were both failing as variable $fname didn't contain the fully qualified file-name. On fixing this the error disappeared!

Thanks again for setting me on the correct path. :-)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved