[mythtvnz] EPG script fails to update mythfilldatabase

Paulgir paulgir at gmail.com
Mon Jun 6 20:28:04 BST 2016


On Mon, 06 Jun 2016 13:09:20 +1200, Jonathan Hoskin  
<jonathan.hoskin at gmail.com> wrote:

> On Mon, Jun 6, 2016 at 11:00 AM, Paulgir <paulgir at gmail.com> wrote:
>>
>>
>> #! /bin/bash
>> wget http://epg.org.nz/freeview.xml.gz
>> gzip -d freeview.xml.gz
>> mythfilldatabase --update --file --sourceid 1 --xmlfile freeview.xml
>> rm freeview.xml
>> exit
>>
>
> Hi Paul,
>
> The coding pattern in that script is problematic, as if you ever end
> up with an invalid freeview.xml.gz, the script will never attempt to
> clean it up.
>
> E.g. if 'wget' fails, then 'gzip -d' fails, then the 'rm' at the end
> will be trying to remove a file that doesn't exist.
>
> Here's some suggestions:
> 1. Use 'wget' with the '-O - ' option, and pipe the output straight
> through 'gzip -d' to generate the xml file on one line
> 2. Use 'rm -f' so the script won't throw errors if the file doesn't exist
> 3. Use '#! /bin/bash -e', so that the script will exit at the first
> failed command, rather than blindly carrying on
> 3. Finally, you could use a 'trap' function, which will ensure the
> clean up code is run at script exit, regardless of failures
>
>
> Here's a quick example:
>
>
> #! /bin/bash -e
>
> function clean_up {
>   rm -f freeview.xml
> }
>
> trap clean_up EXIT
>
> wget -q http://epg.org.nz/freeview.xml.gz -O - | gzip -d > freeview.xml
> mythfilldatabase --update --file --sourceid 1 --xmlfile freeview.xml
>
>
>
> Cheers,
> Jonathan
>
> _______________________________________________

Thanks for the tip.I'll try this.
There's no need for an exit line at the end of this?

-Paul



More information about the mythtvnz mailing list