Register
It is currently Thu Nov 27, 2014 9:57 am

mysqldump usage in bash


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Thu Aug 27, 2009 7:10 am   

Joined: Thu Aug 27, 2009 7:02 am
Posts: 3
Hello everyone..

Im running into quite a large problem in my bash script, I cannot use mysqldump in bash as i require.

The following code is in my script, and if i run it direct in command line or by PHP, it works :-O
Unfortunately not in my bash script:(

Code:
temp="mysqldump -h $DBSource -u $USER -p$PASS $DB $TABLE --where='$Field > $VarStart  AND $Field < $VarEnd' > $TABLE$DumpName"
exec $temp


The error recieved is:
mysqldump: Couldn't find table: ">"

The syntax of mysqldump specifies i must use ' ' for the where flag, i have tried escaping them to no avail.. :(

Your help would be extremely useful..
Arenstar


Top
 Profile  
 PostPosted: Thu Aug 27, 2009 7:23 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Is the $Table variable properly set?
You know it's impossible for us to guess as to what you're trying if you're only pasting 2 lines from something obviously larger.

I'm just guessing because it shouldn't try to use > as the table name, which makes me assume something is missing from the string.

Try doing an echo "$temp" and copy/paste that string that it returns :)

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Thu Aug 27, 2009 7:28 am   

Joined: Thu Aug 27, 2009 7:02 am
Posts: 3
Ok, apologies for my useless post..
Lets try again.

The echo returns the perfect line of code.
in fact im copying and pasting it into a shell, which is not so great for an automated bash script :P

This piece code is enough to recreate the error im having.

Code:
#!/bin/bash

DBSource=10.0.0.6
DBDest=10.0.0.5
DB=$1
TABLE=$2
VarStart=1230764399
VarEnd=1238536800
DumpName=searchwords
Field=day

temp="mysqldump -h $DBSource -u xxxxxx -pxxxxxx $DB $TABLE --where='$Field > $VarStart  AND $Field < $VarEnd' > $TABLE$DumpName"
exec $temp


ensure to pass in the $DB and $TABLE when invoking the script..


Top
 Profile  
 PostPosted: Thu Aug 27, 2009 7:44 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Humm... that's wierd...

Might be something with exec. You don't actually need it since bash will expand the variable to the proper string if executed in this fashion:
Code:
#!/bin/bash
command="echo testing this command"
$command


If that doesn't work either, try using eval.
http://ss64.com/bash/eval.html

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Thu Aug 27, 2009 7:48 am   

Joined: Thu Aug 27, 2009 7:02 am
Posts: 3
Eval.... :) :) :)

EVAL :))

I promised my colleague that if he worked it out, he could spend a night with my girlfriend..
Thank god you worked it out HUH :))

Thanks very much Frederik

Regards

Arenstar


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP