I have a simple shell script that I am running via cron
. I am using it to perform a scheduled git pull
operation (yeah, I know there are probably better methods, but this is another team's repository and I just need to periodically read from it, so I'm opting for a quick and dirty solution).
Anyway, my script does something like this:
#!/usr/bin/bash
if /usr/bin/cd /opt/repos/other-teams-repo
then
echo "success!"
else
echo "fail :("
exit 1
fi
/usr/bin/pwd
if /usr/bin/git pull
then
echo "success on the pull"
else
echo "fail on the pull"
exit 1
fi
From the command line, this works just fine. But when I run it via cron:
57 11 * * 1 /opt/myuser/shell/otheruser-repo-git-pull.sh > /opt/log/repo-pull.git.cronlog 2>&1
In my cronlog, I get this:
success!
/home/myuser
fatal: Not a git repository (or any parent up to mount point /home)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fail on the pull
When I change /usr/bin/cd to cd and /usr/bin/pwd to pwd it works just fine.
I'm just curious if anyone has any insight as to why this might be?
/usr/bin/cd
to do in this context? See for example What is the point of thecd
external command? – steeldriver Jun 06 '23 at 15:39/usr/bin/cd
? – Kamil Maciorowski Jun 06 '23 at 15:53