Avatar of pvinodp
pvinodp
 asked on

how to pass mysql command in a shell variable

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')
LinuxShell ScriptingMySQL Server

Avatar of undefined
Last Comment
pvinodp

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
woolmilkporc

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
pvinodp

ASKER
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.
pvinodp

ASKER
thanks
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy