SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old October 8th, 2004, 03:04 PM
cobracommander cobracommander is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 cobracommander User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
crontab mysqldump syntax

I am trying to make a simple cron script to backup my db using mysqldump. I am entering the script via crontab in plesk.

here is the script:

mysqldump -ufred -p***** email_list2 > /home/httpd/vhosts/mySite.com/httpdocs/dump_`date +%d%m%Y_%H%M`.txt

It works great when i run it at the command line.

But, when run via cron i get this error:
/bin/sh: -c: line 1: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 2: syntax error: unexpected end of file

Also, if I remove the `date +%d%m%Y%H%M` it works too.

Have read many threads, and it seems that this is the syntax people are using.

Any thoughts?
thanks.

Reply With Quote
  #2  
Old October 8th, 2004, 05:09 PM
CeruleanDragon CeruleanDragon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 CeruleanDragon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
What shell?

Just out of curiousity, what shell are you using to run it when you run it manually?

Maybe that shell handles the ' ` characters differently than /bin/sh (which is what it looks like cron is using). I don't know for sure, I'm mostly guessing based on the context of the error. Try switching to /bin/sh yourself and run the line manually and see if it still works.

Reply With Quote
  #3  
Old October 9th, 2004, 12:35 AM
Muthukumar_K Muthukumar_K is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 13 Muthukumar_K User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to Muthukumar_K
Check cron environment variables of SHELL, HOME etc there. Try to export other variables on cron script itself.

Try as,

FILE="/home/httpd/vhosts/mySite.com/httpdocs/dump_$(date +%d%m%Y_%H%M).txt"

mysqldump -ufred -p***** email_list2 > $FILE

Try this out. And tell.

HTH.

Reply With Quote
  #4  
Old May 6th, 2008, 04:38 PM
sfjoe sfjoe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 sfjoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 36 sec
Reputation Power: 0
use the full path

Typically the path in cron is /usr/bin and /usr/sbin so it can't find the date function. Use /bin/date instead and you should be OK.

Reply With Quote
  #5  
Old May 7th, 2008, 02:54 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Novice (500 - 999 posts) Click here for more information
 
Join Date: Mar 2006
Posts: 667 SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level)SimonJM User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 22 h 21 m 9 sec
Reputation Power: 196
If you run that exact command from cron it will not work as cron does not know how to cope with things like `date ...`. You would need to put the actual command within a wrapper script.
__________________
"I feel so miserable without you; it's almost like having you here" - Stephen Bishop

Reply With Quote
  #6  
Old May 7th, 2008, 10:42 AM
sfjoe sfjoe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 sfjoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 36 sec
Reputation Power: 0
You can use date from within cron

Quote:
Originally Posted by SimonJM
If you run that exact command from cron it will not work as cron does not know how to cope with things like `date ...`. You would need to put the actual command within a wrapper script.


In fact you can use any command as you would from the command-line. You have to be careful with escapes and quotes but it all works. Here is a working example of what I use to automate a myldump with cron:
58 13 * * 2,5 mysqldump --user=user --password=pass --host=127.0.0.1 mydb > /var/backups/mydb-`/bin/date +\%Y\%m\%d`

For example, yesterday (Tuesday) at 1:58 PM, it dumped the sql to /var/backups/mydb-20080506

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > crontab mysqldump syntax


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway