Last active
August 29, 2015 14:04
-
-
Save four43/4decc2dfb6476264f324 to your computer and use it in GitHub Desktop.
cron.d script that switches users in order to provide the called script with env vars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Debian/Ubuntu | |
0 2 * * * root su --command="./my-script.sh" other-user -l | |
#RHEL/Fedora/Amazon AMI | |
0 2 * * * root su --session-command="./my-script.sh" other-user -l | |
#Install Script | |
echo " 0 2 * * * root su --session-command=\"./my-script.sh\" other-user -l" | sudo tee /etc/cron.d/my-crond-script | |
chmod 0644 /etc/cron.d/my-crond-script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: Environment variables for the user must go in ~/.profile, not ~/.bashrc. bashrc is only loaded when a new terminal session is created.