Link to home
Start Free TrialLog in
Avatar of XK8ER
XK8ERFlag for United States of America

asked on

run crond a user

hello there,
I would like to know how can I run an script every 5 minutes as user apache..
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Log in as user apache and issue

crontab -e

The user's crontab will be opened by (probably) vi.

Add this line:

*/5 * * * * /path/to/script >/path/to/logfile 2>/path/to/errorlog

Save the file and you're done.

wmp
Avatar of XK8ER

ASKER

any other way to do this rather than to login as apache?
Another possibility is using root's crontab.

Log in as root, issue crontab -e and add

*/5 * * * * su - apache -c "/path/to/script >/path/to/logfile 2>/path/to/errorlog"

On some systems you can also place a file into the /etc/cron.d directory, containing a line in the format

*/5 * * * * apache /path/to/script >/path/to/logfile 2>/path/to/errorlog

ASKER CERTIFIED SOLUTION
Avatar of mcolomera
mcolomera

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It's good practice to never touch /etc/crontab.

Better use the /etc/cron.d directory!