Search code examples
linuxbashshellcron

Why is my cronjob not properly calling commands within .sh scripts?


I'm having an issue with cronjobs in Ubuntu where its calling some commands and not others

cronjob

30 * * * * /bin/bash /home/path/script/start.sh >> /tmp/test.txt

start.sh

#!/bin/bash

cd /home/path/script

echo "Its working"

/usr/bin/git fetch
/usr/bin/git pull origin

echo "git"

/usr/bin/python3 /home/path/script/main.py &

echo "end"

/var/log/syslog

CRON[362212]: (ubuntu) CMD (/bin/bash /home/path/script/start.sh >> /tmp/test.txt)

test.txt

Its working
Updating n83aw46..215iebd
git
end

When I git log it still shows the previous git commit and when I run ps -ef | grep .py nothing shows up.

I have confirmed cron daemon is running. ps -ef command also works with my test python script. I've also verified that both the main.py and start.sh files has chmod +x


Solution

  • @Philippe Your suggestion of adding another err log ... >> /tmp/test.txt 2> /tmp/test.err helped me resolve the issue.

    There was a conflict with local changes and git pull. So I had to stash, pull then re-apply the stash.