简体   繁体   中英

linux cron job isn't running

I have a Ubuntu Server 10.

At the root cron I have a script to run every day at the same hour.

Running the script manually it's run fine, but in the cron it doesn't run.

At the syslog I got this:

Aug 23 09:22:01 database CRON[6884]: (root) CMD (./bkp.sh >> /tmp/bkp.log)
Aug 23 09:22:01 database CRON[6883]: (CRON) error (grandchild #6884 failed with exit status 2)

I found the possible source of the problem, I added some LOGs (echo) in the script...

During script execution, it exits on a "function" definition...

It seems that I have no access to command "function"

How can I solve this?

Shell scripts launched by cron must carefully specify the environment that they're running in. Shells run within cron will be non-interactive, meaning that they will not read /etc/profile , where $PATH is typically set. This means that you will need to specify the paths to all executables called in your script.

If you run a lot of cron scripts, it may be worth your time to write a small shell script which will define and export environment variables to be used inside your script, starting with $PATH .

Here's a link i got while googling for 'cron environment variables'. It may help. There are many others like it :)

将脚本放在以下目录中,然后它将每天运行。

/etc/cron.daily/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM