1

I'm writing a script to pull the DB information from a wp-config.php file and use that to login to mysql and then run a command to create a new user.

Yes this sounds like a major hacker script but I'm more trying to troubleshoot.

For purposes of shortening up this post I'll summarize the first part:

db=user_database
usr=user_databaseuser
ps=database_password
qr=mysql command

mysql --user=$usr --password=$ps $db

Now here is where I have troubles, I have another variable $qr that I'm trying to call once logged into mysql. I have tried:

-e $qr 

on the end of that mysql command to login. When I try to use that method it does not do anything. I have also tried:

mysql --user=$usr --password=$ps $db < cat $qr or < echo $qr

With these ones I get a syntax error reporting cat and echo as an unknown command.

4
  • 1
    What do you mean by "doesn't work"? Error messages? Please be more specific, otherwise people cannot help. Commented Apr 24, 2013 at 18:48
  • 1
    foo < cat x doesn't make any sense. What you probably mean is cat x | foo The argument to < or > must be a filename, not another command. Commented Apr 24, 2013 at 18:55
  • Quote $qr (and if it still doesn't work, use set -x...) Commented Apr 24, 2013 at 19:04
  • Note BTW that username, password, database, and a lot more, can more easily be set by using a --defaults_file. Commented Apr 24, 2013 at 19:05

1 Answer 1

3

Use

echo $qr | mysql --user=$usr --password=$ps $db

or

mysql --user=$usr --password=$ps $db -e "$qr"
Sign up to request clarification or add additional context in comments.

1 Comment

thanks sorry for the long reply, thats what I ended up using a variation of

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.