Why is my cron.daily script not running?
Over the years when setting up servers I have run into the various ways that your cron.daily or cron.hourly scripts manage to fail to run. Today I ran into a new reason which I don't recall running into before, maybe something has changed or maybe I just never ran into it.
I ran into the problem on a Ubuntu 16.04 LTS server - I placed a script in
/etc/cron.daily/my_script.sh but it was not running.
I checked all the usual suspects, the reasons I was aware of that cause a cron script to be ignored:
- The script must have the
- The script did not depend on certain environment variables being set (for example if you rely on
$HOMEto be set, you may need to define it yourself). Cron scripts do not have all the same environment variables that you have when you are logged in to a shell, so the script can work when you run it but fail when cron runs it.
- The script did not rely on a customized
PATHto execute commands. The
PATHthat cron gives your script will be minimal, and if you have made customizations to it they may not show up. The best way around this is to use the full path to your commands (use the
whichcommand to help figure this out).
But my problem was not any of the above. I found that you can execute the
run-parts command in a test mode to see which scripts it would call in a directory. You can run it like this (it will not execute any of the scripts, it just outputs which ones it would execute):
run-parts --test /etc/cron.daily
My script was not listed in the output! Well, that was comforting at least but why was it not listed? It turns out you cannot have a file extension on the script, so by renaming the script from
my_script it works!
- The 15 Essential UNIX commands - July 29, 2005
- Howto Backup your Mac incrementally over SSH - March 10, 2006
- Unix Job processing - November 28, 2005
- Top 20 Internet Security Vulnerabilities of 2005 - November 23, 2005
- What is the difference between ASCII Chr(10) and Chr(13)
- Fixinator and Foundeo Security Bundle
- Running CFML on AWS Lambda with FuseLess Slides
- Updating Java on ColdFusion or Lucee
- ColdFusion returning empty response with server-error: true
- Careful applying CF11u16, CF2016u8, CF2018u2
- Sessions don't work in Chrome but do in IE
- csrfVerifyToken does not invalidate the token