[colug-432] Bash fun

Tom Hanlon tom at functionalmedia.com
Sun Nov 1 12:26:25 EST 2009


Thanks Matt,

Good to know that eval is not needed.

Another question, suppose I wanted to throttle this script.

I want to run only 10 requests for second ?

Part of the issue is this will spawn one mysql connection per line.

The connection will be immediately dropped but we would still face:
	authentication, thread generation , execution , disconnect.
	authentication, thread generation , execution , disconnect.
	authentication, thread generation , execution , disconnect.

Rather than.
	authentication, thread generation
		execution
		execution
		execution
		......
	disconnect
		




Unfortunate but I do not know how to batch explain from inside mysql.

MySQL does take batch jobs as  source.sql > mysql >>outfile.txt

So I might try and work it that way.

Batch 100 lines, connect and run,

Batch 100 lines, connect and run.

If I find I have to run this on a production box.. well it would be  
nice to not spawn one mysql connection per line.

Thanks,

Tom
On 1 Nov 2009, at 11:34, Matt Meinwald wrote:

> Eval doesn't do what you described, but from what you are using it  
> for, you don't need it at all.  If you just put the line in the  
> script:
> mysql -u user -ppass -e "explain select this from that">>file.out
> then it will run that line.  Eval is effectively called on every  
> line of your script without you having to do anything.
>
> The original behavior you described, of forking, would be  
> accomplished with an ampersand, e.g.
> mysql -u user -ppass -e "explain select this from that">>file.out &
> This will continue running the script simultaneously with the  
> command.  I would caution against using this, because if the  
> commands take different amounts of time to run, their outputs will  
> likely be out of order in the output file.
>
> On 11/01/09 11:10, Tom Hanlon wrote:
>> Colug...
>>
>>
>> too funny, every time I post a question I find the answer the  
>> moment I
>> hit send.
>>
>> Looks like I want "eval"
>>
>> Anyhow... any general bash advice in regards to writing good scripts,
>> good tutorials, etc.
>>
>> I was tempted to go with Python because I could use the python
>> practice, but I could also use the bash practice.
>>
>> This will be run on linux, but also open solaris....
>>
>> Is open solaris fair game for discussion ? How about open solaris  
>> with
>> bulged capacitors on Motherboard ;-)
>>
>> So bash open solaris, environment issues.. ?? Are there any I need to
>> be aware of.
>>
>> --
>> Tom
>>
>>
>>
>> On 1 Nov 2009, at 11:02, Tom Hanlon wrote:
>>
>>> Colug,
>>>
>>> I am writing a script that takes a file of MySQL queries. I want to
>>> read that file and then run explain for each query in the file and
>>> gather a subset of the output generated.
>>>
>>> So basic process is.
>>>
>>> given file
>>>
>>> select this from that;
>>> select that from this;
>>>
>>> I want to run
>>>
>>> mysql -u user -ppass -e "explain select this from that">>file.out.
>>> mysql -u user -ppass -e "explain select that from this">>file.out.
>>>
>>> I am reading the lines from the file.. no problem, I am assigning  
>>> them
>>> to variables.
>>>
>>> The exec, or eval or whatever it takes to fork a process and keep on
>>> going is holding me up a little bit.
>>>
>>> #!/bin/bash
>>> while read line
>>> do
>>> echo  $line;
>>> ######
>>> # exec seems to exit
>>> #
>>> ## exec who;
>>> done
>>>
>>>
>>>
>>> Thanks,
>>>
>>> Tom
>>> _______________________________________________
>>> colug-432 mailing list
>>> colug-432 at colug.net
>>> http://lists.colug.net/mailman/listinfo/colug-432
>>
>> _______________________________________________
>> colug-432 mailing list
>> colug-432 at colug.net
>> http://lists.colug.net/mailman/listinfo/colug-432
>
>
> _______________________________________________
> colug-432 mailing list
> colug-432 at colug.net
> http://lists.colug.net/mailman/listinfo/colug-432



More information about the colug-432 mailing list