Run-parts vs. user crontab execution
From Brandonhutchinson.com
(Difference between revisions)
(New page: One caveat when running programs via '''run-parts''' (e.g., ''/etc/cron.hourly, /etc/cron.daily, etc.) vs. user crontabs is the '''HOME''' environment variable. By default, '''HOME''' is ...) |
|||
| (One intermediate revision not shown.) | |||
| Line 1: | Line 1: | ||
| - | One caveat when running programs via '''run-parts''' (e.g., ''/etc/cron.hourly, /etc/cron.daily, etc.) vs. user crontabs is the '''HOME''' environment variable. | + | One caveat when running programs via '''run-parts''' (e.g., ''/etc/cron.hourly'', ''/etc/cron.daily'', etc.) vs. user crontabs is the '''HOME''' environment variable. |
| - | By default, '''HOME''' is set to '''/''' in ''/etc/crontab'' | + | * By default, '''HOME''' is set to '''/''' in ''/etc/crontab'', so all scripts executed via '''run-parts''' have a '''HOME''' of '''/'''. |
| - | + | ||
| + | * By default, '''HOME''' is the home directory in ''/etc/passwd'' of the crontab owner in user crontabs. This can be overwridden by including a '''HOME''' line in user crontabs. | ||
This caused me problems when I tried to execute a MySQL backup script via '''run-parts''' that depended on ''~/.my.cnf'' in the user's home directory. As a workaround, I modified the script to set the HOME environment variable rather than make a global change in ''/etc/crontab'' for all '''run-parts''' scripts. | This caused me problems when I tried to execute a MySQL backup script via '''run-parts''' that depended on ''~/.my.cnf'' in the user's home directory. As a workaround, I modified the script to set the HOME environment variable rather than make a global change in ''/etc/crontab'' for all '''run-parts''' scripts. | ||
Current revision
One caveat when running programs via run-parts (e.g., /etc/cron.hourly, /etc/cron.daily, etc.) vs. user crontabs is the HOME environment variable.
- By default, HOME is set to / in /etc/crontab, so all scripts executed via run-parts have a HOME of /.
- By default, HOME is the home directory in /etc/passwd of the crontab owner in user crontabs. This can be overwridden by including a HOME line in user crontabs.
This caused me problems when I tried to execute a MySQL backup script via run-parts that depended on ~/.my.cnf in the user's home directory. As a workaround, I modified the script to set the HOME environment variable rather than make a global change in /etc/crontab for all run-parts scripts.
