0

This cron tqsk doesn't work:

[main_usr@localhost ~]$ sudo crontab -l  -u root
0 * * * * /home/main_usr/cron_test1.sh > /home/main_usr/cron_test1_out.sh.out 2>&1

[main_usr@localhost ~]$ 

And

$ ls -al cron_test1.sh
-rwxr-xr-x 1 main_usr main_usr 293 Apr  8 05:12 cron_test1.sh

As you can see, there's a new line in the cron tasks. And the file exists and is executable. The task was created a day ago. It should've run once in an hour. Nonetheless, 'cron_test1_out.sh.out' hasn't been created.

Why?

jijino
  • 1

2 Answers2

0

I had the same issue some time ago.

Adding /bin/bash fixed it for me.

Example:

0 * * * * /bin/bash /path_to_your_script/script.sh > /output_directory

Reason: When running a shell script you have to define where the script should be executed, so probably you have to use /bin/sh, /bin/zsh or what ever to run the script within.

Cron itself does not know where to run the script.

Please also check /var/log/syslog and /var/mail/root to see the reason.

0

Cron tasks are run with /bin/sh and a blank environment, so sometimes you may need to source your bash profile or some other environment file, or optionally, include the environment variables in the cron file. PATH is usually the biggest offender. By default, path is set to /usr/bin:/bin, so if your script refers to any executables that are not in these two directories without the full path, your cron will fail. You can set any of the environment variable in the crontab with a simple KEY=VALUE, such as

PATH=/usr/bin:/bin:/usr/local/bin
Mike Breed
  • 136
  • 2