Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to upload dynamically created log file from my local box to my FTP server. This all happens in a cron job (crontab) I run every night. It creates the file using:

30 00 * * * touch ~/Desktop/logs/"log$(date +'\%m\%d\%y')"

Which works just fine. However, when I try to upload the file using the same syntax:

50 00 * * * curl -T ~/Desktop/logs/"log$(date +'\%m\%d\&y')" -u user:pass ftp://example.com/logs/

It gives me the following error:

date: extra Operand

I also tried it without escaping the the %:

curl -T ~/Desktop/logs/"log$(date +'%m%d%y')" -u user:pass ftp://example.com/logs/

Which works in the normal command line, but when executed via the crontab, gives the following error:

/bin/sh: Syntax error: Unterminated quoted string

Any ideas how to successfully upload the daily log to my server?

share|improve this question
    
Dude don't use %m%d%Y, use %Y-%m-%d! Or equivalently date -I. –  poolie Oct 18 '11 at 22:05
    
Thanks for the tip. Don't know what I was thinking when I wrote that! –  Louis Bataillard Oct 20 '11 at 20:19
add comment

1 Answer

up vote 1 down vote accepted

The way I would normally specify the date in a cron job is not to have quotes around the whole name and to use backticks around the date command, so:

50 00 * * * curl -T ~/Desktop/logs/log`date +'\%m\%d\%y'` -u user:pass ftp://example.com/logs/

Although I would expect the $(date ...) syntax to work aswell.

(Oh and I'm assuming the ampersand before the y in the second cron job is a typo in the question - but if it's also in your cron job that will be a problem.)

share|improve this answer
    
Thank you. That has worked. I don't know why the syntax I used to create the file (touch ~/Desktop/logs/"log$(date +'\%m\%d\%y')") wouldn't work with rsync! –  Louis Bataillard Oct 20 '11 at 20:20
    
rsync, or curl? rsync expects remote filenames to possibly contain globs and quoting, and if you were actually using rsync that might explain why it didn't work. –  poolie Oct 23 '11 at 23:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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