I have a shell script to automate a git commit and push every night:
auto_git_push.sh
#!/bin/sh
function automate(){
git add .
git commit -am "automated push $(date +"%Y-%m-%d")"
git push -u
}
cd ~/htdocs
automate
If I run this command, the script works as expected: . ~/bin/auto_git_push.sh
However, with this crontab line (set to every minute for testing)
* * * * * sh /home/hookedonwinter/bin/auto_git_push.sh
I get the following error:
/home/hookedonwinter/bin/auto_git_push.sh: 3: Syntax error: "(" unexpected
What is causing this syntax error?
Thanks!
Edit based on accepted answer:
Changed the script to:
#!/bin/bash
automate() {
git add .
git commit -am "automated push $(date +"%Y-%m-%d")"
git push -u
}
cd ~/htdocs
automate
And the crontab line to:
* * * * * /bin/bash /home/hookedonwinter/bin/auto_git_push.sh