Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to pass mysql command in  a shell variable

Posted on 2013-12-26
3
Medium Priority
?
603 Views
Last Modified: 2013-12-26
for i in "${cmd_array[@]}"
        do
                ${i} >> $logFile
        done

THe variable cmd_array has many elements . One of the element is a mysql command.
It is defined as :
cmd_array[1]='mysql -uroot -prootDB -e "show full processlist" | grep Query  | grep -v "show full processlist'

THis command fails to run. When i executed the script using "sh -x " , i am able to see his command is being executed as
mysql -uroot -prootDB -e '"show' full 'processlist"' '|' grep Query '|' grep -v '"show' full processlist

LIMITATION: I can't handle this command separately inside the for loop, as it is a generic code. How do i form the mysql query so that it gets executed.

I have another command [default command] which has no issues:
cmd_array=('cat /proc/${process_pid}/status')
0
Comment
Question by:pvinodp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 39739822
Try prefixing the command with "eval":

cmd_array[1]='eval mysql -uroot -prootDB -e "show full processlist" | grep Query  | grep -v "show full processlist"'

The last double quote is missing in your post - I assume that's a typo here and not in the original code?

If the above doesn't work for whatever reason you could prefix all commands with "eval". The commands which already run without issues will also run with "eval".

...
         do
                eval ${i} >> $logFile
        done
...
0
 

Author Comment

by:pvinodp
ID: 39739884
yes that was a typo. But my code does have the double quotes.
Thanks it worked. THere was no need to have the eval inside for loop.
0
 

Author Closing Comment

by:pvinodp
ID: 39739890
thanks
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question