<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 27, 2015 at 10:08 AM, Paulgir <span dir="ltr"><<a href="mailto:paulgir@gmail.com" target="_blank">paulgir@gmail.com</a>></span> wrote:<br><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"><div class=""><div class="h5">On Fri, 11 Sep 2015 01:13:48 +1200, Stephen Worthington <<a href="mailto:stephen_agent@jsw.gen.nz" target="_blank">stephen_agent@jsw.gen.nz</a>> wrote:<br>
<br>
<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">
On Thu, 10 Sep 2015 20:47:58 +1200, you wrote:<br>
<br>
<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">
I have been trying to setup a daily cron job to udpate my listings<br>
from <a href="http://epg.org.nz/freeview.xml.gz" rel="noreferrer" target="_blank">http://epg.org.nz/freeview.xml.gz</a><br>
<br>
My script runs fine if I run in manually but it fails when run from<br>
cron with these errors:<br>
<br>
2015-09-10 07:55:52.485142 W  This application expects to be running a<br>
locale that specifies a UTF-8 codeset, and many features may behave<br>
improperly with your current language settings. Please set the LC_ALL<br>
or LC_CTYPE, and LANG variable(s) in the environment in which this<br>
program is executed to include a UTF-8 codeset (such as<br>
'en_US.UTF-8').<br>
2015-09-10 07:55:52.485154 W  Cannot locate your home directory.<br>
Please set the environment variable HOME<br>
2015-09-10 07:55:52.485158 E  Failed to init MythContext, exiting.<br>
<br>
Here is my script:<br>
#! /bin/bash<br>
echo "$(date) : starting epg import " >> /tmp/epggrubber.log<br>
PATH=/usr/sbin:/usr/bin:/sbin:/bin<br>
HOME=/home/mythtv<br>
LANGUAGE=en_NZ:en<br>
LANG=en_NZ.UTF-8<br>
wget -O /tmp/freeview.xml.gz <a href="http://epg.org.nz/freeview.xml.gz" rel="noreferrer" target="_blank">http://epg.org.nz/freeview.xml.gz</a> >><br>
/tmp/epggrubber.log 2>&1<br>
gunzip /tmp/freeview.xml.gz >> /tmp/epggrubber.log 2>&1<br>
mythfilldatabase --update --file --sourceid 2 --xmlfile<br>
/tmp/freeview.xml --update >> /tmp/epggrubber.log 2>&1<br>
rm /tmp/freeview.xml<br>
echo "$(date) : finished epg import " >> /tmp/epggrubber.log<br>
exit<br>
<br>
As you can see I am setting the environment variables for home and language.<br>
<br>
Anyone know what I need to do to make it work?<br>
<br>
Cheers,<br>
Daniel Hughes<br>
</blockquote>
<br>
Doing this properly is a tricky problem that took me days to get<br>
working to my satisfaction.  So I will set out what I did and why.<br>
<br>
mythfilldatabase needs to be run by a mythtv group user.  If you want<br>
to run it from a cron job, then you need to run it from a user cron<br>
job, not a system one.  The easiest user to do this from is normally<br>
the one you use for mythfrontend.  The mythtv user is often not fully<br>
set up properly, and its crontab may not work.  Any cron job needs to<br>
have it full environment set up as part of the script that is being<br>
run, as it will not inherit any environment from cron.<br>
<br>
So, login as the mythfrontend user from ssh or a terminal window.  Put<br>
your script in say /home/<mythfrontend user>/bin.  Make sure your<br>
EDITOR variable points to your favourite command line editor (eg vi,<br>
nano), then run the command "crontab -e" which will bring up the user<br>
crontab for that user using $EDITOR.  Edit the crontab to add your<br>
script, save the crontab file and exit.<br>
<br>
Note that manually trying to edit the user crontab file does not work<br>
properly - you need to use the crontab command to do it.<br>
<br>
I use two scripts for doing my EPG.  By setting things up with the two<br>
scripts, the first script can log all the output of the second script<br>
to a log file, which makes it easy to see exactly what has gone wrong<br>
when the EPG processing fails.  My first script (epg_temp) is run by<br>
cron, and sets up the environment for the second script, and also<br>
rotates its log file.  The second (epg_temp.sh) does my EPG processing<br>
and runs mythfilldatabase.  The cron script (epg_temp) uses a helper<br>
script logrotate.sh that has been added to sudoers so that it can<br>
rotate the logs.<br>
<br>
I have put epg_temp and logrotate.sh on my web server so you can see<br>
how they work:<br>
<br>
  <a href="http://www.jsw.gen.nz/mythtv/epg_temp" rel="noreferrer" target="_blank">http://www.jsw.gen.nz/mythtv/epg_temp</a><br>
  <a href="http://www.jsw.gen.nz/mythtv/logrotate.sh" rel="noreferrer" target="_blank">http://www.jsw.gen.nz/mythtv/logrotate.sh</a><br>
<br>
The logrotate.sh file lives in my /home/stephen/bin directory, but is<br>
chown root:root in order to be able to access the log files in<br>
/var/log/mythtv.  You also need a logrotate.conf file in<br>
/home/<mythfrontenduser>/.logrotate, which also needs to be chown<br>
root:root:<br>
<br>
    <a href="http://www.jsw.gen.nz/mythtv/logrotate.conf" rel="noreferrer" target="_blank">http://www.jsw.gen.nz/mythtv/logrotate.conf</a><br>
<br>
There needs to be a file using the name of the mythfilldatabase user<br>
in /etc/sudoers.d to allow logrotate.sh to work.  This is what I have<br>
in my /etc/sudoers.d/stephen file:<br>
<br>
stephen ALL=NOPASSWD:/home/stephen/bin/logrotate.sh<br>
<br>
The sudoers file needs to be chown root:root and readonly for user and<br>
group only, or it will not work.  It can not have any write<br>
permissions at all.<br>
<br>
I have not posted my epg_temp.sh file, as it is too specific to how I<br>
do EPG and not a good example to follow (it really needs to be<br>
re-written).<br>
<br>
_______________________________________________<br>
mythtvnz mailing list<br>
<a href="mailto:mythtvnz@lists.linuxnut.co.nz" target="_blank">mythtvnz@lists.linuxnut.co.nz</a><br>
<a href="http://lists.ourshack.com/mailman/listinfo/mythtvnz" rel="noreferrer" target="_blank">http://lists.ourshack.com/mailman/listinfo/mythtvnz</a><br>
Archives <a href="http://www.gossamer-threads.com/lists/mythtv/mythtvnz/" rel="noreferrer" target="_blank">http://www.gossamer-threads.com/lists/mythtv/mythtvnz/</a><br>
</blockquote>
<br></div></div>
I run the following:<br>
<br>
#! /bin/bash<br>
wget <a href="http://epg.org.nz/freeview.xml.gz" rel="noreferrer" target="_blank">http://epg.org.nz/freeview.xml.gz</a><br>
gzip -d freeview.xml.gz<br>
mythfilldatabase --update --file --sourceid 1 --xmlfile freeview.xml<br>
rm freeview.xml<br>
exit<br>
<br>
It's been working for several years<br>
<br>
-Paul<div class=""><div class="h5"><br></div></div></blockquote><div><br></div><div>Why when we have tv-grab_nz=py which works with mythbackend. No cron, so environment problems.<br></div><div> </div></div></div></div>