2

I'm trying to automate a job I'm duing daily by hand. I ended up writing a sh script to push a git repository.

the script is located at /home/autogit-project.sh

And looks like this:

#!/bin/sh
cd /var/www/project

git add *
timestamp(){
   date +"%d.%m.%Y um %H:%M"
}
git commit -am "Auto Server Commit $(timestamp)"
git push --repo https://[user]:[password]@github.com/[organisation]/[repo].git

when running the script via $ sh autogit-project.sh it works.

For testing purpose I want to run the script every minute. My Crontab looks like this:

@daily /home/anotherscriptthatworks.sh
* * * * * /home/autogit-project.sh

anotherscriptthatworks.sh is in the same directory with the same user right. the script writes a log file, so I know it works. My autogit-project.sh however does not and I'm struggling to find out why. Any ideas or help is very welcome.

lechnerio
  • 884
  • 1
  • 16
  • 44

1 Answers1

3

First, You have to make sure that autogit-project.sh is have executed permissions

chmod a+x autogit-project.sh

Second, you can write the cron task in the following form (run crontab -e and paste the below cronjob)

* * * * * /bin/bash -l -c 'cd /var/www/project && ./autogit-project.sh >> /home/cron_log.log 2>&1'

you can check the cron jobs of the user supposed to run the task, by expecting

crontab -l 
or 
crontab -l -u $user_name
Kevin C
  • 4,851
  • 8
  • 30
  • 64
Al-waleed Shihadeh
  • 2,697
  • 2
  • 8
  • 22