run cron as user code example

Example 1: run cron job as specific user

# Crontab Running as a Specific User
# From root's crontab sudo crontab -e, you can use:
1 1 * * * su username -c "/path/to/your/script.sh"

Example 2: run cron job as specific user

# Crontab Running as a Specific User
# Only /etc/crontab and the files in /etc/cron.d/ have a username field. In that file you can do this:
1 1 * * * username /path/to/your/script.sh

Example 3: run cron job as specific user

# Crontab Running as a Specifi User
# Through Command Line, you use the User's Actual crontab like this:
sudo crontab -u username -e