Verify crontab file
The file /etc/crontab
has to end with a blank line. If at the end of the file there is no blank line (ie empty), Mr. Cron refuses to work.
Example:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the 'crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
*/2 * * * * root /bin/hola.sh
#<--- Esto es una linea en blanco
Check that crontab is started:
Then there is the option that the service is not started, to check that the cron is started first put: pgrep cron
, if you do not get an answer execute service cron start
(with root permissions, or failing sudo)
Summon the program with the absolute path:
Probably your problem is that you 'assume' that your program will be executed with sh, but you have to keep in mind that cron does not always know what to use to execute the command. That's why modify the order changing:
*/2 * * * * root /bin/hola.sh
for
*/2 * * * * root /bin/sh /bin/hola.sh
* assuming that /bin/hola.sh is the path of your program and that /bin/sh
is the location of sh. This last value can be obtained by executing the which sh
command.