What user do scripts in the cron folders run as? (i.e. cron.daily, cron.hourly, etc)
If I put a script in /etc/cron.daily on CentOS what user will it run as? Do they all run as root or as the owner?
Solution 1:
They all run as root
. If you need otherwise, use su
in the script or add a crontab entry to the user's crontab (man crontab
) or the system-wide crontab (whose location I couldn't tell you on CentOS).
Solution 2:
Edit: my answer doesn't actually apply in this case, see Zoredache's comment below. Sorry, all (esp. geekosaur). Kyle, note that if you want to run a script regularly as a non-root user, the following may be helpful; just do it through cron.d rather than cron.{hourly,daily,weekly,monthly}.
I hate to contradict, but I fear that geekosaur isn't quite right. They run as root except where specified otherwise. Here's part of my CentOS box's /etc/cron.d/munin
file:
# cron-jobs for munin
MAILTO=root
1-56/5 * * * * munin /usr/share/munin/munin-limits --force
Note how, on the substantive line (line 3), there's a username specified before the executable. This particular cron entry runs as user munin, so provided your cron is similar to CentOS 5's (vixie-cron-4.1-77), you should be able to do likewise.