Cron – How to run a crontab as another user

cron

I want to have a scheduled crontab run on a daily basis but not as the root user.
Reasons being that this is a simple backup and cleanup job and I don't want any accidents.
The backup folder will have permissions for user 'mysql-backup' (for example) and I want the crontab to only run as user mysql-backup. Obviously I don't want the mysql-backup user logged in or anything like that for the crontab to work.

Best Answer

You can either edit the desired user's crontab:

crontab -e -u mysql-backup

or use su or sudo to change to that user at runtime in root's crontab.

Related Topic