Re: Script: OScam "überwachung"
Verfasst: Di 17. Apr 2012, 09:12
Hab ich mich falsch ausgedrückt meinte natürlich was zwischen den "" steht.
Code: Alles auswählen
#!/bin/bash
#
#### CONFIG - START
## OScam WebIf with SSL? [1=yes , 0=no]
OSssl="0"
## /path/to/oscam.conf?
OScfg="/var/etc/oscam.conf"
## Cards to monitor
CARD[1]="sky"
CARD[2]=""
CARD[3]=""
CARD[4]=""
## OScam's Logfile?
OSlog="/var/log/ipc/OScam.log"
## monitoring Error message
OSerror="ERROR Phoenix_GetStatus: ioctl error in card detection for %CARDNAME%"
## reporting logfile for this script?
OStolog="/var/log/ipc/OScam.error"
#### CONFIG - END
OSip="127.0.0.1"
[ "$OSssl" = 1 ] && URL="https://" || URL="http://"
# Simple URL encoding
proc_url_encode() {
out=${1//%/%25}; out=${out//\{/%7B}; out=${out//\}/%7D}; out=${out//|/%7C};
out=${out//\\/%5C}; out=${out//^/%5E}; out=${out//~/%7E}; out=${out//[/%5B};
out=${out//]/%5D}; out=${out//\`/%60}; out=${out//#/%23}; out=${out//>/%3E};
out=${out//\$/%24}; out=${out//&/%26}; out=${out//+/%2B}; out=${out//,/%2C};
out=${out//\//%2F}; out=${out//:/%3A}; out=${out//;/%3B}; out=${out//=/%3B};
out=${out//\?/%3F}; out=${out// /%20}; out=${out//</%3C};
echo $out
}
proc_parse_cfg() {
i=0
while read line; do
line=$(echo $line | sed -e 's/ //g')
if [[ "$line" =~ ^[^#]*= ]]; then
cfg_name[$i]=$(echo $line | cut -d'=' -f 1)
cfg_value[$i]=$(echo $line | cut -d'=' -f 2-)
((++i))
fi
done < $1
}
get_cfg_value() {
i=0
for name in ${cfg_name[*]}; do
[ "$1" = "$name" ] && echo "${cfg_value[$i]}" && break
((++i))
done
}
proc_get_infos() {
proc_parse_cfg $OScfg
WEBPORT=$(get_cfg_value httpport)
[ -z "$WEBPORT" ] && "ERROR: WebIf isnt enabled! Abort!" && exit 1
USERNAME=$(get_cfg_value httpuser)
if [ ! -z "$USERNAME" ]; then
PASSWORD=$(get_cfg_value httppwd)
URL="$URL"`proc_url_encode "${USERNAME}"`":"`proc_url_encode "${PASSWORD}"`"@${OSip}:${WEBPORT}"
else
URL="${URL}$OSip:$WEBPORT"
fi
}
proc_get_infos
for card in ${CARD[*]}; do
ERRORmsg=${OSerror//%CARDNAME%/$card}
founds=`tail -10 $OSlog | grep "$ERRORmsg" | wc -l`
if [ $founds >= 1 ]; then
echo "`date +%d-%b-%Y` `date +%H:%M:%S`: $card Card lost" >> $OStolog
wget --spider "$URL/readers.html?label=${card}&action=disable"
wget --spider "$URL/readers.html?label=${card}&action=enable"
fi
done
exit 0