Running as a specific user, will I have to add the script location into PATH?
You usually don't need to modify the PATH environment variable when you're using absolute paths such as you're doing now with /opt/scripts/wf_venv/bin/python /opt/scripts/wf_api_linux.py 2>&l /opt/scripts/log.txt
As sysadmin you have several options to create scheduled batch jobs that run under a different user ID:
As explained in this answer: set up a personal crontab for that user. Jobs in a personal crontab will always run under the user ID of their owner.
Note that when you as the administrator set up a personal crontab for another user, that user will be able to modify and delete that cron job specification, undoing your work.
Alternatively you can schedule a system job from the system crontab. The system crontab (typically /etc/crontab
and/or drop-in files in /etc/cron.d/
) is owned by root and can't be modified by unprivileged users. The job specification in the system crontab supports an extra field not present in personal crontab files: field #6 needs a username, such as xfeautomation
of the user ID that will be used to execute the job.
The syntax you posted is correct for an entry in /etc/crontab
or a drop-in file like /etc/cron.d/wf_api_linux
0 * * * * xfeautomation /opt/scripts/wf_venv/bin/python /opt/scripts/wf_api_linux.py 2>&l /opt/scripts/log.txt
Since you're logging all output and errors not a concern, but normally cron will email standard output and errors to root when you set up a system crontab and directly to the user when using a personal crontab.
As far as I know effectively both methods result in the same conditions for the job and aside from the concerns about ownership of the job spec and emails, they are equivalent.