<div dir="ltr">On Mon, May 13, 2013 at 11:33 AM, Drew Tomlinson <span dir="ltr"><<a href="mailto:drew@mykitchentable.net" target="_blank">drew@mykitchentable.net</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">After upgrading from 0.24 to 0.26, all my commflag jobs exited on error 140. After learning that it was because of the commflag command and fixing that in the general setup, I wanted to commflag all the recordings that had erred. With some reading and fiddling, I came up with this:<br>
<br>
mysql mythconverg -umythtv -pmythtv < ~/commflag.sql | sed '1d; s/-//g;s/://g' | awk '{print "/usr/bin/mythcommflag --queue --chanid", $1, "--starttime",$2$3}'<br>
<br>
Commflag.sql contains:<br>
SELECT chanid, starttime FROM `mythconverg`.`recorded`where commflagged <> 1;<br>
<br>
Which prints this:<br>
<br>
/usr/bin/mythcommflag --queue --chanid 2581 --starttime 20130513045900<br>
/usr/bin/mythcommflag --queue --chanid 1278 --starttime 20130513045900<br>
/usr/bin/mythcommflag --queue --chanid 3031 --starttime 20130509045900<br>
<br>
So I added a 'for' loop with a 'do echo' to test:<br>
<br>
for i in "`mysql mythconverg -umythtv -pmythtv < ~/commflag.sql | sed '1d; s/-//g;s/://g' | awk '{print "/usr/bin/mythcommflag --queue --chanid", $1, "--starttime",$2$3}'`"<br>
<br>
do<br>
<br>
echo ${i}<br>
<br>
done<br>
<br>
<br>
But the output is just one long line:<br>
<br>
/usr/bin/mythcommflag --queue --chanid 2581 --starttime 20130513045900 /usr/bin/mythcommflag --queue --chanid 1278 --starttime 20130513045900 /usr/bin/mythcommflag --queue --chanid 3031 --starttime 20130509045900<br>
<br>
I've read up on 'awk' and tried adding '\n' but this doesn't seem to have any effect. I've also read about $IFS and tried setting that to '\n' but still no help.<br>
<br>
Thus I have these questions:<br>
<br>
1. Is a 'for' loop the proper loop to use? I fiddled with 'while' and 'read' and 'read line' but couldn't get those to work either.<br>
<br>
2. How do I get the newline added so I can make this a script?<br>
<br>
3. Am I duplicating something that already exists in MythTV?<br>
<br>
Thanks for your time.<br>
<br>
Cheers,<br>
<br>
Drew<br></blockquote><div><br></div><div style>I use something like this to get at mysql results in bash:</div><div><br></div><div><br></div><div style>current_line=0</div><div style># read query results into $data, one line at a time<br>
</div><div>mysql --user=$MYSQLUSER --password=$MYSQLPASSWORD $MYSQLDB < myquery.sql | while read -r data</div><div>do</div><div> current_line=$(($current_line+1))</div><div> IFS=' ' # tab as separator</div>
<div> line=(${data//NULL/0}) # replace NULL with a more useful value, split $data into an array using IFS</div><div> unset IFS # back to default</div><div><br></div><div style> # $line contains the current 'record' as an array</div>
<div style> echo "$current_line -> ${line[0]} - ${line[1]}"</div><div style>done<br></div><div style><br></div><div style><br></div><div style>Good luck!</div><div style>--Glenn</div><div style><br></div></div>
</div></div>