0

I have the following command

  mysql -u root -ppass myDB -e "select * from table limit 10;"

which when I run it from a linux server it works normally (10 tuples are displayed)

When the following is added in a bash file

  echo 'mysql -u root -ppass myDB -e select * from table limit 10;' >> /root/test.log

nothing happens. In the log file, only the echo string is being displayed. Can someone please help me in this?

4
  • You (?) have written a code that outputs a string to a file. That's correct. And probably you better start with explanation what you want to achieve Commented Apr 17, 2012 at 11:34
  • just to play it safe: have you noticed that the database and passwords are different on the two commands you posted, haven't you? And you have just shared your pass with us. Commented Apr 17, 2012 at 11:34
  • @zerkms - I want to write the command result in the log instead of the string Commented Apr 17, 2012 at 11:53
  • Then don't echo the string into the log file. Echo just outputs its arguments - it doesn't execute anything. Try typing "echo remove all my files" - you'll get "remove all my files" on your screen. Echo just echoes - it doesn't execute. Commented Apr 17, 2012 at 11:58

2 Answers 2

4

that is because you just echo your command as a string and redirect the output of echo to the log file. You do nothing else ;-)

Just run the command as you would do on the command line and redirect the output of mysql command (instead of echo) to your logfile:

#!/bin/sh
mysql -u root -ppass myDB -e "select * from table limit 10;" >> /root/test.log
Sign up to request clarification or add additional context in comments.

Comments

-1

This is because

mysql -u root -ppass myDB -e "select * from table limit 10;"

Is not the same as

mysql -u root -ppass myDB -e select * from table limit 10;

Try using this:

echo 'mysql -u root -ppass myDB -e "select * from table limit 10;"' >> /root/test.log

And then actually invoke the command

mysql -u root -ppass myDB -e "select * from table limit 10;" >> /root/test.log

Comments

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.