Linux cron tasks not executed

Some days ago have found an issue trying to execute some tasks via “cron” on my linux box, seems that cron ignores my tasks….

To execute tasks on cron you can:

  • Edit the “crontab” file for the current user (with command “crontab -e“), and put on them some tasks.

Every user allowed to execute cron tasks (take a look at /etc/cron.allow and /etc/cron.deny ) have its own crontab file with their tasks (and these tasks can be reviewed with the command “crontab -l“).

  • Also if you have root permissions you can leave the script on some of the “cron” directories under /etc:

/etc/cron.houry

/etc/cron.daily

/etc/cron.weekly

/etc/cron.monthly

The scripts located under these directories must be executed on the defined basis (every hour, day, week or month).

 

Ok, so fine, so good. I’m little lazzy, this second method seems faster and my scrip fits on one of these execution windows (is a daily script)… then I move the script to the folder /etc/cron.daily.

Some days after the scrip have no executions ¿?

After some digging have found the reason of the “no execution”… the main cron process responsible of execute the scripts inside of these folders (called “run-parts”) not like some characters on scripts names, and these “not liked” characters include “dots”, then all my scripts (ending with .sh due are shell scripts) are ignored.

After remove the extension of the scripts all began to execute on the expected time frames.

Also found that is possible to execute a “dry-run” of the “run-parts” process to check if you script is one of the candidates to be executed.


root@VirtualBox:~# run-parts --test /etc/cron.daily
/etc/cron.daily/0anacron
/etc/cron.daily/apache2
/etc/cron.daily/apport
/etc/cron.daily/apt-compat
/etc/cron.daily/bsdmainutils
/etc/cron.daily/cracklib-runtime
/etc/cron.daily/dpkg
/etc/cron.daily/google-chrome
/etc/cron.daily/logrotate
/etc/cron.daily/man-db
/etc/cron.daily/mlocate
/etc/cron.daily/ntp
/etc/cron.daily/passwd
/etc/cron.daily/popularity-contest
/etc/cron.daily/update-notifier-common
/etc/cron.daily/upstart
root@VirtualBox:~# echo "echo HOLA" > /etc/cron.hourly/say_hola.sh
root@VirtualBox:~# chmod 755 /etc/cron.hourly/say_hola.sh
root@VirtualBox:~# run-parts --test /etc/cron.hourly
root@VirtualBox:~# mv /etc/cron.hourly/say_hola.sh /etc/cron.hourly/say_hola
root@VirtualBox:~# run-parts --test /etc/cron.hourly
/etc/cron.hourly/say_hola

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s