1826909 Members
3004 Online
109705 Solutions
New Discussion

about crontab job

 
juno2
Super Advisor

about crontab job

i write a script to download file " sz -a /tmp/* " , it is Ok to download file to my harddisk ( on Netterm ), but if I make it to the crontab job as " * * * * * sz -a /tmp/* " , then nothing download to my harddisk , can suggest why ? thx
6 REPLIES 6
Umapathy S
Honored Contributor

Re: about crontab job

hi,
cron environment is completly different from shell. Make sure you give the whole path of the file and command also (if its not in /usr/bin) in crontab.

HTH,
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Robert-Jan Goossens
Honored Contributor

Re: about crontab job

Hi,

First of all where is the command sz ?
/usr/local/bin/sz ???

second use this
* * * * * "/???/sz -a /tmp/*" > /dev/null 2>&1

Hope it helps,

Robert-Jan.
Massimo Bianchi
Honored Contributor

Re: about crontab job

Hi,
in addition to Umaphaty's suggestion, it's best not to use wildcards in crontab, sometimes you can incur into problem.

And i suggest you to change the location of the file source: in HPUX /tmp is used for almost anything, you may download much more than needed.

HTH,
Massimo
James R. Ferguson
Acclaimed Contributor

Re: about crontab job

Hi:

The most common reason a script works from a shell session but not when 'cron'ed is the sparse environment 'cron' offers. Most notably, 'cron' supplies only the environmental variables HOME (the user's-home-directory), LOGNAME, a PATH consisting of (only) '/usr/bin:/usr/sbin:' and a SHELL variable of '/usr/bin/sh'. This means that your '$HOME/.profile' with any/all of the variables you may define, is *not* offered to the crontas's environment.

One workaround is to source (read) your $HOME/.profile as part of the crontask. A better solutino is to declare *all* the variables you need within your script or within a file that your script sources (reads) as it begins executing.

Regards!

...JRF...
Paula J Frazer-Campbell
Honored Contributor

Re: about crontab job

Hi

Cron must have all the environmental variables it requires set.

Also in your script give the full path to every command.


When using cron

One to watch out for is:-

WRONG
cd /
rm *

RIGHT
rm //*

If the cd fails then the rm will be done in root dir.


Paula
If you can spell SysAdmin then you is one - anon
twang
Honored Contributor

Re: about crontab job

I think you must include full path to the command in the crontab:
* * * * * /usr/bin/sz -a /tmp/*
And I usually create a script to do so, export the search path and related environment variables in the script, like this(.cronprofile export all variables):
. .cronprofile
/usr/bin/sz -a /tmp/*