The Little Guy Posted May 1, 2012 Share Posted May 1, 2012 I have a bash script that runs as a cron, and one of the commands in the script requires sudo to work. My question is how do I pass a password to sudo? Here is the bash cron script: #!/bin/bash PHP_FPM_FOUND=`top -n 1 -b | grep -o php-fpm | wc -l` if [ "$PHP_FPM_FOUND" = "0" ] then sudo /etc/init.d/php-fpm start echo "Started php-fpm" else echo "Didn't Start php-fpm" fi Quote Link to comment Share on other sites More sharing options...
Philip Posted May 1, 2012 Share Posted May 1, 2012 Set your account to no password in the sudo file would be the easiest (and laziest) fix. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 1, 2012 Author Share Posted May 1, 2012 I tried this (/etc/sudoers): ryannaddyps ALL=NOPASSWD: /etc/init.d/php-fpm ryannaddyps ALL=(ALL) ALL It didn't work, does it look right? Quote Link to comment Share on other sites More sharing options...
trq Posted May 1, 2012 Share Posted May 1, 2012 Assuming you have root access you would be better off installing this cron in roots crontab. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 1, 2012 Author Share Posted May 1, 2012 I didn't think I could add the cron to root on my vps, but I guess I can.... It seems to be working now... Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 1, 2012 Author Share Posted May 1, 2012 I will know 100% if it worked tomorrow, php-fpm seems to stop around 2AM (my time), so I will update this then. Thanks for the help! Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 2, 2012 Author Share Posted May 2, 2012 So the script worked last night! My server was still running when I woke up this morning! So... I think this is solved! Thanks for the suggestion! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.