Skip to content

Instantly share code, notes, and snippets.

@four43 four43/cron.d.example.sh

Last active Aug 29, 2015
Embed
What would you like to do?
cron.d script that switches users in order to provide the called script with env vars
#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
@four43

This comment has been minimized.

Copy link
Owner Author

four43 commented May 27, 2015

NOTE: Environment variables for the user must go in ~/.profile, not ~/.bashrc. bashrc is only loaded when a new terminal session is created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.