Friday, January 29, 2016

Bash Script Won't Run in Cron



Here's what I have in my crontab:



*  *  *  *  * /bin/bash /home/user_name/script.sh



Here's what's in the file:



#!/bin/bash

cd /var/www/sites/site1
sudo svn update *

cd /var/www/sites/site2
sudo svn update *



The script is set to +x.



Any ideas on why it won't run in cron? It runs fine when I run it manually.


Answer



Any reason you have /bin/bash in cron invocation? The #!/bin/bash in the script itself should do the same thing. Also make sure that the script is configured to executable (chmod +x/chmod 755). Verify that you want to run the program under your account, otherwise specify the user with the sudo -u "USERNAME" command. Also check and make sure that your account (or the account you want it to run under) has the NOPASSWD option added in /etc/sudoers (more info here:http://www.gratisoft.us/sudo/sudoers.man.html).


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...