#!/bin/sh
# USING ****************************************************
# 1. Switch OSCam into debug mode 4!
# 2. Start this script
# tiers_grabber.sh
# tiers_grabber.sh m (manual zapping)
# **********************************************************
#
# USER SETUP ***********************************************
# OSCam logfile
oscamLogfile='/tmp/oscam.log'
# reader name:
readerName='<READER_NAME>'
# receiver IP:
receiverIP='<RECEIVER_IP>'
# scan only CAID (or leave it empty)
scanCAID='098C'
# save tiers to:
outFile='/tmp/tiers.csv'
# grepSwitches receiver (i = case insensitive):
grepSwitches='-i'
# grepSwitches i686 (i = case insensitive; a = read ASCII):
#grepSwitches='-ia'
# sleep n seconds
sleepSeconds=4
# auto zap command or empty for manual zapping (key up = 103; key down = 108)
#cmdAutoZap=''
cmdAutoZap='wget -O - -q "http://'"$receiverIP"'/web/remotecontrol?command=103" | grep "\(<\|</\)e2resulttext" | tr -d '\n' | sed "s/.*<e2resulttext>\(.*\)<\/e2resulttext.*/\\1\n/"'
# get channel name by receiver:
#cmdGetProgramName='wget -O - -q "http://'"$receiverIP"'/web/getcurrent" | grep "\(<\|</\)e2servicename" | tr -d "\n" | sed "s/.*<e2servicename>\(.*\)<\/e2servicename.*/\\1\n/"'
# get channel name by OSCam log:
cmdGetProgramName='grep '"$grepSwitches"' "(ecm).*'"$readerName"'.*'"$scanCAID"'" '"$oscamLogfile"' | tail -n 1 | sed "s/ */ /g" | sed "s/^.*) -//g" | sed "s/^ //g"'
# END USER SETUP *******************************************
cntProxy=0
if [ ! -e "$outFile" ]; then
touch "$outFile"
fi
if [ ! -z "$1" ] && [ "$1" == "m" ]; then
cmdAutoZap=''
fi
while [ 1 -eq 1 ]; do
if [ ! -z "$scanCAID" ]; then
if [ 0 -eq `grep $grepSwitches -cm 1 "(ecm).*$readerName.*$scanCAID" $oscamLogfile | tail -n 1` ]; then
echo "$scanCAID not found!"
if [ ! -z "$cmdAutoZap" ]; then
eval "$cmdAutoZap"
else
echo "Please zap to the next channel or stop this script with \"CTRL+C\""
fi
sleep 1
continue
fi
fi
curTear=`grep $grepSwitches -A1 'Decrypted' $oscamLogfile | tail -n 1 | sed 's/ */ /g' | cut -d " " -f16,17 | sed 's/ //g'`
if ! `echo "$curTear" | grep -q '^[0-9A-F]\{4\}$'`; then
echo "Invalid tear: \"$curTear\""
echo "Please zap to the next channel"
sleep $sleepSeconds
# exit 1
elif [ "$curTear" == "0000" ]; then
echo "Irrelevant tier: $curTear"
if [ ! -z "$cmdAutoZap" ]; then
eval "$cmdAutoZap"
else
echo "Please zap to the next channel or stop this script with \"CTRL+C\""
fi
sleep 1
continue
fi
curChan=`eval "$cmdGetProgramName"`
if `echo "$curChan" | grep -q '^[0-9]\{4\}/[0-9]\{2\}/[0-9]\{2\}'`; then
echo "Proxy or unknown channel \"$curChan\"! I will retry it in 1 second..."
cntProxy=`expr $cntProxy + 1`
if [ $cntProxy -gt 5 ]; then
if [ ! -z "$cmdAutoZap" ]; then
eval "$cmdAutoZap"
else
echo "Please zap to the next channel or stop this script with \"CTRL+C\""
fi
fi
sleep 1
continue
fi
curLine="$curTear;$curChan"
if [ -z "`grep -m 1 $grepSwitches "$curLine" $outFile`" ]; then
echo "$curLine" >> $outFile
echo "$curLine saved!"
cntProxy=0
else
echo "$curLine already saved!"
if [ ! -z "$cmdAutoZap" ]; then
eval "$cmdAutoZap"
else
echo "Please zap to the next channel or stop this script with \"CTRL+C\""
fi
sleep 1
continue
fi
# echo $curLine
sleep $sleepSeconds
done
exit 0