Yes, the nc or socat you're using needs to be the right one in order to write to a unix socket.
The 'wget -O' will overwrite epg.xml, so you don't need the rm. You don't give a path for epg.xml in the wget line, so the script would only work as expected if you're in /home/hts/.
I'd modify your script a little:
#!/bin/bash
LOGFILE="/home/hts/xmltvlog/xmltv.log"
EPGFILE="/tmp/epg.xml"
echo "Download starting..." > $LOGFILE
echo "Time: $(date)" >> $LOGFILE
wget -O $EPGFILE 'http://myiptv.com:826/xmltv.php?username=me&password=me'
cat $EPGFILE | sudo socat - UNIX-CONNECT:/home/hts/.hts/tvheadend/epggrab/xmltv.sock
echo "" >> $LOGFILE
echo "Time: $(date)" >> $LOGFILE
echo "EPG Updated successfully." >> $LOGFILE
The single '>' in the "Download starting" line overwrites any previous log file.
I have a script that can be useful in these sorts of situations:
$ cat /usr/local/bin/agefile
#!/bin/sh
#
# usage: agefile FILE1 to age FILE1 to FILE1.1 and FILE1.2
# agefile FILE1 FILE2 to age FILE1 and replace with FILE2
#
OLD="$1"
OLDER="$1".1
OLDEST="$1".2
if [ -s $OLD ];then
if [ -e ${OLDEST} ]
then
rm ${OLDEST}
fi
if [ -e ${OLDER} ]
then
mv ${OLDER} ${OLDEST}
fi
if [ -e ${OLD} ]
then
mv ${OLD} ${OLDER}
fi
fi
if [ $# -eq 2 ]
then
mv $2 ${OLD}
fi
If you want to use this, make sure you give it executable permission and make sure /usr/local/bin/ is in $PATH.
You could add this to the script above:
#!/bin/bash
LOGFILE="/home/hts/xmltvlog/xmltv.log"
EPGFILE="/tmp/epg.xml"
agefile $LOGFILE
agefile $EPGFILE
echo "Download starting..." > $LOGFILE
...
This will give you xmltv.log xmltv.log.1 xmltv.log.2 epg.xml epg.xml.1 epg.xml.2 so you can check the previous version of each file if something goes wrong.
Be careful to always run the script as the same user that the crontab is for. For example if you run it as root, you'll get epg.xml owned by root, and when the crontab operates, it won't be able to overwrite the file.