Search code examples
shellcronsudo

Running a Shell Script as a Cronjob


I have a written a shell script to automate a build process.

The script checksout some code from an SVN repo, compiles and builds the code before extracting the built binary files and storing these in a central location.

I can manually execute the script ./autobuild.sh and it runs perfectly. There are a few sudo commands executed throughout the script, but I echo the password through for the first sudo command and the password holds for the entire time:

echo mypassword! | sudo -S make clean

When I add executing the script as a crontab it fails to complete all the tasks. I've tried to add it as a cronjob for the normal and root users.

Running crontab -e on my normal user account, I want the script to run at ten past midnight every day:

10 0 * * * /home/username/autobuild.sh

Also running a 32-but Cent OS 7 install with all the latest updates installed.

Can anyone provide any suggestions as to why it might work manually but not when run through a cron?


Solution

  • Try this

    10 0 * * * /bin/bash /home/username/autobuild.sh