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:


ssh-agent -s | head -n 2 > "$SSHTMPFILE"

function killsshagent {
    /bin/kill $SSH_AGENT_PID
trap killsshagent EXIT

if [ -f "$SSHTMPFILE" ]; then
    source "$SSHTMPFILE"
    rm "$SSHTMPFILE"


if [ `hostname` == "mrbeancomp.local" ]; then
    cd $REPODIR
    cvs update -dP  > "$HOME/log/log.txt"

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)


killsshagent added in program so ssh-agent is not dangling.


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.


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?

  • For the love of god, use something besides cvs. It's 2014. – Faheem Mitha Oct 9 '14 at 20:18
  • @Faheem, your comment is irrelevant. – qazwsx Oct 9 '14 at 20:26
  • As irrelevant as it might seem, he's actually right - modern DVCSes are much better integrated with ssh. But that's not the main reason for abandoning cvs. – peterph Oct 9 '14 at 20:33
  • Try running the ssh in verbose mode - ssh -vvv. That should give you some indication of what is wront with the authentication. Given the error, I suppose the script is running under the correct user, but you might want to double-check. Also note, that you are spawning new ssh-agent instance every time the script runs and don't kill them. – peterph Oct 9 '14 at 20:40
  • How do I "running the ssh in verbose mode"? Change ssh-agent in the above to ssh-agent -vvv ? I added kill so the ssh-agent process is killed. – qazwsx Oct 9 '14 at 22:45

At a guess (I'm not a unix expert, but have had a similar issue with cron jobs not running), what user are you executing the task as? Does that user have all the permissions needed to access everything you need?

I suspect not (the error sort of says so! :-D ).

If you logout from the working user and log in as a different user, does the bash script work still? If not, then that does sort of help.

The solution we used was to run the task as a specific user.

There are several ways to do this it seems (aren't there always). I can't comment on the merits of one over the other - that will be for you to decide. How to specify in crontab by what user to run script?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.