I'm trying to automate version-control repository update in crontab. The following script
/home/usr/mrbean/bin/update.sh
works in interactive Bash command-line:
#!/bin/bash
ROOTPATH="/home/user/mrbean/temp/"
cd $ROOTPATH
SSHTMPFILE="${ROOTPATH}ssh-agent.cf"
ssh-agent -s | head -n 2 > "$SSHTMPFILE"
function killsshagent {
/bin/kill $SSH_AGENT_PID
}
trap killsshagent EXIT
if [ -f "$SSHTMPFILE" ]; then
source "$SSHTMPFILE"
ssh-add
rm "$SSHTMPFILE"
fi
killsshagent
if [ hostname
== "mrbeancomp.local" ]; then
REPODIR="/home/usr/mrbean/repo/"
cd $REPODIR
cvs update -dP > "$HOME/log/log.txt"
fi
I then add
@hourly /home/usr/mrbean/bin/update.sh
The script works by itseful when invoked in interactive Bash shell but not via crontab. It gives errors and sent to system mail /var/mail/mrbean
:
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).
cvs [update aborted]: end of file from server (consult above messages if any)
### [Update]
killsshagent
added in program so ssh-agent
is not dangling.
### [Update]
Tried an adapted program on a Git repository and experienced same issue. Mr. Bean isn't allowed to immediately abandon this CVS repo and switch to a new Git one.
### [Update]
I have multiple identity files in $HOME/.ssh/
. Is it possible that when running from crontab, I need to specify which identity file to use? If so, how?
Asked by qazwsx
(177 rep)
Oct 9, 2014, 08:03 PM
Last activity: May 18, 2015, 12:39 PM
Last activity: May 18, 2015, 12:39 PM