LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   svnadmin crontab issue (http://www.linuxquestions.org/questions/linux-software-2/svnadmin-crontab-issue-4175452450/)

thund3rstruck 03-02-2013 09:00 PM

svnadmin crontab issue
 
Just checked last year's source code backups and to my shock there weren't any! When I ssh'd into the subversion server I had 52 new mail messages!

Code:

/bin/sh: 1: Syntax error: end of file unexpected (expecting ")")
Looking at the crontab:
Code:

00 1 * * 1  svnadmin dump /home/svn/collection | gzip > /media/remote/Backup/svnserver01/$(date +%Y-%m-%dT%H:%M).backup.svn.gz
I ran the command directly in the terminal and it worked fine. What's wrong with running this command in a user crontab?

eeekster 03-02-2013 11:45 PM

Perhaps changing to this would do it:

Code:

00 1 * * 1  svnadmin dump /home/svn/collection | gzip > /media/remote/Backup/svnserver01/`date +%Y-%m-%dT%H:%M`.backup.svn.gz

chrism01 03-04-2013 01:13 AM

Could be the fact that the default PATH in cron is minimal. Always recommended to specify absolute path to all cmds/files used or (better) put the whole thing in a script, call that and source/specify required PATH.
EG start by cd'ing into your dir, then copy PATH definition from your env.

linosaurusroot 03-04-2013 02:28 AM

I'm shocked it took longer than a week to notice this .. stuff that hasn't been tested should be assumed not to work.

colucix 03-04-2013 02:32 AM

The real problem is that % signs need to be escaped, since they have a special meaning in crontab. The % signs in crontab will be changed to newline and everything after the first % sign is interpreted as standard input to the command. Therefore you crontab entry will result in:
Code:

00 1 * * 1  svnadmin dump /home/svn/collection | gzip > /media/remote/Backup/svnserver01/$(date +
Y-
m-
dT
H:
M).backup.svn.gz

and the parenthesis highlighted in red is responsible of the error. You should change the date command into:
Code:

date +\%Y\%m\%dT\%H:\%M
Hope this helps.

thund3rstruck 03-04-2013 07:53 AM

Quote:

Originally Posted by linosaurusroot (Post 4904144)
I'm shocked it took longer than a week to notice this .. stuff that hasn't been tested should be assumed not to work.

Ha... yea, it took 52 weeks; and even then I only noticed it because I was performing and annual backups audit. I guess it's a good thing that Subversion server didn't go down this year.

thund3rstruck 03-04-2013 08:07 AM

Quote:

Originally Posted by colucix (Post 4904146)
You should change the date command into:
Code:

date +\%Y\%m\%dT\%H:\%M
Hope this helps.

Makes sense! I'll know tomorrow morning if it worked or not. Thanks!

----------UPDATE-----------

Yup, that works. I wonder why characters have to be escaped in a crontab definition but not in a standard bash script? Is it because cron doesn't use /bin/sh to run?


All times are GMT -5. The time now is 03:18 AM.