LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
LinkBack Search this Thread
Old 02-16-2009, 04:34 PM   #1
rmunsch
LQ Newbie
 
Registered: Feb 2009
Posts: 2

Rep: Reputation: 0
Question [Solved] cron job fails, but command in crontab succeeds when directly entered


Hello,

I have the following crontab listing:

00 04 * * * mysqldump -p<blah> <dbname> > /root/mydb-`date +%Y-%m-%d`.sql; gzip -f /root/mydb-`date +%Y-%m-%d`.sql; smbclient //mynetwork-dc/MySQLBackups <moreblah> -Usqlbackups -c "put mydb-`date +%Y-%m-%d`.sql.gz"

Leaving aside the kludgy nature of this for now, if i run the whole silly command directly, it works perfectly in just a few seconds. The DB is dumped, zipped, and thrown over the network to the target drive, where it lands safely.

When the cronjob runs, however, it chokes. I get this in the logs:

(root) CMD (mysqldump -p<blah> <dbname> > /root/mydb-`date +)

it eats it on the percentage sign. Now, inside the backtics, directly entered, it executes the command and substitutes the result as you'd expect. I have not yet been able to figure out a quoting scheme inside the crontab, however, that works. It dies there every time. i don't get it o_O.

TIA, and Halp!,

Rob

SOLUTION:
Assumed it was quoting, when i shoulda been escaping. Solution was to backslash the percent signs, thusly:

00 04 * * * mysqldump -p<blah> <dbname> > /root/mydb-`date +\%Y-\%m-\%d`.sql; gzip -f /root/mydb-`date +\%Y-\%m-\%d`.sql; smbclient //mynetwork-dc/MySQLBackups <moreblah> -Usqlbackups -c "put mydb-`date +\%Y-\%m-\%d`.sql.gz"

and, while even uglier than before, works perfectly and consistently.

Last edited by rmunsch; 02-16-2009 at 05:43 PM. Reason: Solved
 
Old 02-16-2009, 04:45 PM   #2
jkzfixme
Member
 
Registered: Sep 2006
Location: Orange County, NY
Distribution: Ubuntu, Solaris, Android
Posts: 329
Blog Entries: 21

Rep: Reputation: 52
have you considered using a pre-existing script such as this one ? I find it works out great and would work around your current dilema as I could not see why it would not work.

Regards
JKZfixme
 
Old 02-16-2009, 05:27 PM   #3
rmunsch
LQ Newbie
 
Registered: Feb 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jkzfixme View Post
have you considered using a pre-existing script such as this one ? I find it works out great and would work around your current dilema as I could not see why it would not work.

Regards
JKZfixme
Interesting script, but i think i end up with the same issue. The goal is a remote (Windows) server share, which i'm using smbclient to put the backup on.

The script you mention will run in crontab and make a mysql backup on the local disk. That part i have working; i'd still have to do something to move the backup to the remote server, which is my goal.

The problem is that crontab doesn't seem to like the %-signs in the date command; and since both my script and the one you mention timestamp the files, i'd need to include a way in the crontab of getting the current, timestamped file name.

Does anyone know what sort of quoting scheme i need to prevent cron from choking on the % arguments to the date command?

Solved: edited original post.

Last edited by rmunsch; 02-16-2009 at 05:44 PM. Reason: solved
 
  


Reply

Tags
backticks, bash, cron, crontab


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell prompt works, cron job fails btuley Linux - General 1 11-13-2008 11:40 AM
Command not working in cron job, but works fine in root Roosta21 Linux - Software 4 11-22-2007 08:08 AM
cron job and boot command Thulemanden DamnSmallLinux 3 11-08-2006 12:22 AM
Cron Job help...how to write this command? pxumsgdxpcvjm Linux - Newbie 2 09-05-2006 04:42 AM
mediacheck fails but install succeeds!! frolicchap Fedora - Installation 1 01-20-2006 12:20 AM


All times are GMT -5. The time now is 05:16 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration