08 Oct, 2008, Zeno wrote in the 1st comment:
Votes: 0
Any thoughts as to why this crontab isn't working?
5 4 * * sun rm -rf /home/xxx/backup/biyg*
5 3 * * * /home/xxx/bkup
5 6 * * sat mutt -s "BIYG backup `date +%m-%d-%y`" -n -F /dev/null -a /home/xxx/backup/biyg_backup_`date +%y%m%d`.tgz xxx@gmail.com < /dev/null


The first two work, but the mutt one doesn't. Now if I copy-paste that mutt syntax, it'll work. But for some reason I'm not getting emails from that cron.
08 Oct, 2008, David Haley wrote in the 2nd comment:
Votes: 0
Normally crontab generates logs of errors or sends you email with the errors. Can't you look at those to figure out what it's complaining about?

When you look at the output of crontab -l, do you see that entry? (Presumably you do, but just checking…)
08 Oct, 2008, Zeno wrote in the 3rd comment:
Votes: 0
Yeah, that's from crontab -l.

Not seeing any emails in root, not sure where logs would be.
08 Oct, 2008, David Haley wrote in the 4th comment:
Votes: 0
I think that the email gets sent to whichever user entered the crontab.

You might have to check that none of those characters are being treated specially by cron. Not sure where the logs are either, I've only ever gotten them over email.
08 Oct, 2008, Zeno wrote in the 5th comment:
Votes: 0
Ah, forgot I was under another user.
Quote
N 3 root@xxx.biyg.org Sat Sep 20 06:05 24/942 "Cron <zeno@xxx> mutt -s "BIYG backup `date +"

Quote
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file


I probably need escapes somewhere?
08 Oct, 2008, David Haley wrote in the 6th comment:
Votes: 0
It looks like the percent signs might be confusing it. Try escaping those?
08 Oct, 2008, Zeno wrote in the 7th comment:
Votes: 0
Before I do that, how am I going to test this? Is there some sort of switch in cron where I can run a command under cron at will?
08 Oct, 2008, David Haley wrote in the 8th comment:
Votes: 0
Unfortunately, I don't know. You could figure out what shell cron is using – probably just /bin/sh – and try executing the commands in that shell, not your normal user shell.
08 Oct, 2008, Zeno wrote in the 9th comment:
Votes: 0
It does say /bin/sh, but running it under that seems to work.
sh-3.2$  mutt -s "BIYG backup `date +%m-%d-%y`" -n -F /dev/null -a /home/xxx/backup/biyg_backup_`date +%y%m%d`.tgz xxx@gmail.com < /dev/null
sh-3.2$
08 Oct, 2008, David Haley wrote in the 10th comment:
Votes: 0
Sorry, I'm stumped then. I haven't played with cron jobs all that much. I'd try escaping characters that look like they might do something, and change the job frequency to be every minute or something while testing. :shrug: Hopefully somebody will have a better idea.
08 Oct, 2008, Zeno wrote in the 11th comment:
Votes: 0
I'm being told:
Obviously, if you copied your line correctly, there is a missing backtick.
Backticks mean the same as old "eval", actually yours was intended to add the
result of a formatted date (but that's malformed as well) to the subject.
As an example, date "+%d.%m.%Y" gives the current date in day.month.year notification.
Your line most likely should look more like mutt -s "BIYG backup `date +"%y-%m-%d"`
08 Oct, 2008, David Haley wrote in the 12th comment:
Votes: 0
Oh yeah… maybe the format does need to be in quotes, after the plus, in which case you'd have to move around the quotes and back ticks. So you'll need to escape the inner quotes.
08 Oct, 2008, quixadhal wrote in the 13th comment:
Votes: 0
Zeno said:
Any thoughts as to why this crontab isn't working?
5 4 * * sun rm -rf /home/xxx/backup/biyg*
5 3 * * * /home/xxx/bkup
5 6 * * sat mutt -s "BIYG backup `date +%m-%d-%y`" -n -F /dev/null -a /home/xxx/backup/biyg_backup_`date +%y%m%d`.tgz xxx@gmail.com < /dev/null


The first two work, but the mutt one doesn't. Now if I copy-paste that mutt syntax, it'll work. But for some reason I'm not getting emails from that cron.


A couple things to note…
I've never actually tried using non-numeric date arguments, so you might swap "sat" for 6 and see if that works.

It's usually best to give full pathnames to everything, just to ensure the shell that gets spawned by cron will find it… so date might want to be /bin/date, or /usr/bin/date… wherever you have it. Same for mutt.

I also think date requires quotes for its arguments.

You might also be running into problems with the back-tick execution. Try…
(D=$(/bin/date "+%m-%d-%y"); /usr/bin/mutt -s "BIYG backup $D" -n -F /dev/null -a "/home/xxx/backup/biyg_backup_$D.tgz")


Hope one of those helps!
08 Oct, 2008, Zeno wrote in the 14th comment:
Votes: 0
Actually I think the entire problem is that I just didn't RTFM.
Quote
Percent-signs (%) in the command, unless escaped with backslash (\),
will be changed into newline characters, and all data after the first % will
be sent to the command as standard input.
08 Oct, 2008, David Haley wrote in the 15th comment:
Votes: 0
Heh, so you didn't try escaping the percent signs? :wink:
08 Oct, 2008, Zeno wrote in the 16th comment:
Votes: 0
I hadn't after someone told me the backticks were the issue.

I escaped the percent signs and left the backticks as I originally had them and it works just fine…
08 Oct, 2008, quixadhal wrote in the 17th comment:
Votes: 0
*chuckle*

LSD - Learn Something Daily.

I didn't RTFM either. :)
0.0/17