Yeah, I know it's classic. I've googled it all around, but still it doesn't work. I have the following script:

 #First go to SVN repo folder
cd $svnrepos

# Just make sure we have write access to backup-folder
if [ -d "$bakdest" ] && [ -w "$bakdest" ] ; then
  # Now $repo has folder names = project names
  for repo in *; do
    # do svn dump for each project
    echo "Taking backup/svndump for: $repo"
    echo "Executing : svnadmin dump $repo > $bakdest/$repo-$bakdate.svn.dump \n"
    # Now finally execute the backup
    svnadmin dump $repo > $bakdest/$repo-$bakdate.svn.dump
    # You can go an extra mile by applying tar-gz compression to svn-dumps

    # We also would like to save the dump to remote place/usb
      # USB/other directory exists, copy the dump there
      echo "Going to copy $repo dump to $baktousb directory...\n"
      /usr/bin/scp -v $bakdest/$repo-$bakdate.svn.dump $baktousb/$repo-$bakdate.svn.dump
  echo "Unable to continue SVN backup process."
  echo "$bakdest is *NOT* a directory or you do not have write permission."

# End of backup script
echo "\n\n================================="
echo " - Backup Complete, THANK YOU :-]"

everything works fine in shell, but when It's executed as cron job it simply doesn't scp (but does create a backup). Yes, I have an empty paraphrase. Can't get why it doesn't work.

  • Where is $svnrepos defined? Also, you may want to check out rsync.
    – Bernhard
    Dec 24, 2012 at 9:44
  • See my comment to @Rahul Patil. I thought about using rsync, but it relies on ssh anyway, so I didn't want to add another level of abstraction/complication, because of my humble needs towards this script.
    – J-unior
    Dec 24, 2012 at 9:48
  • Check this answer for a method how to troubleshoot a cron job: unix.stackexchange.com/a/56503/16841
    – jippie
    Dec 25, 2012 at 11:03
  • What platform are you on?
    – jippie
    Dec 25, 2012 at 11:04

2 Answers 2


The issue is that you are probably running ssh-agent in your interactive environment but do not in cron and that your ssh key filename is different from the default filenames.

To solve this you can either explicitly specify the ssh key in your scp commandline, i.e. scp -i $SSH_KEY_FILENAME or specify an appropriate ~/.ssh/config entry for your host, i.e:

Host backuphost
    IdentityFile SSH_KEY_FILENAME

To test your script you can try to run it via env -i /path/to/your/script which should reset your environment and mimic the cron environment.

  • /usr/bin/scp -i /home/username/.ssh/authorized_keys $bakdest/$repo-$bakdate.svn.dump $baktousb/$repo-$bakdate.svn.dump doesn't seem to help :-(
    – J-unior
    Jan 1, 2013 at 8:39
  • 1
    @J-unior authorized_keys is not the private key Jan 1, 2013 at 15:32

Assuming Linux.

1.Default shell in which a cron job is executed is very limited (sh), start your script with a:


2.STDOUT and STDERR in cron jobs are redirected system mail. Check your mailbox.

3.Check your script using the method in this answer: https://unix.stackexchange.com/a/56503/16841

4.Check your PATH variable while in cron environment and the location of all binaries you call. Where is svnadmin located? Use full path name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .