«•» GeoSharing Worlds No.1 Satellite Forum «•»

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Oscam Scripts To Check Client Timeout & Auto Restart

-=EYEDREAM=-

Administrator
Staff member
Administrator
Joined
Dec 18, 2018
Messages
87
Reaction score
108
Points
33
Here is a script to check if a user gets a high ecm say over 1000ms and it will restart Oscam automatically:
Set the clientimeout to "lets say 1000 ms".

The scipt i use on debian:
Dont forget to change

SIZE=
LOG=,
STARTSCRIPT=


and change the crontab !!!

Code:
#!/bin/bash

# accepable number of timeouts CAN'T BE LESS THAN THAT 2 "s client timeout=1000 ms, fallback timeout=700 ms, cache delay=0 ms"
SIZE="4"

# oscam init script
STARTSCRIPT="/etc/init.d/oscam"

# log file
LOG="/var/log/oscam.log"


CHECK="`tail -200 $LOG |grep -v grep |grep -c timeout`"

# If the the word "timeout" appears more times then SIZE ...
if [ "$CHECK" -gt "$SIZE" ]; then

# backup the log
#mv "$LOG" /var/log/oscamtimeout$(date '+%Y_%m_%d_%H:%M').log

# delete the log
rm "$LOG"
# logging restarts of oscam
echo 'oscam restarted becouse of timeot at' $(date '+%Y_%m_%d_%H:%M') >> /var/log/oscamtimeouts.log

#killing oscam
kill -KILL $(pidof oscam)

# wait 2 sec

sleep 2

# start oscam
"$STARTSCRIPT" start

else
echo 'nincs' > /dev/null
exit 1
fi
1- you oscam folder are /usr/local/bin/
2- You named the above check script as oscamtimeout.sh
3- Create another script (On path /usr/local/bin/ ) to start - stop and restart oscam and u called osc


Code:
#!/bin/sh
FOLDER="/usr/local/bin/"
cd /$FOLDER/
PROG="oscam"
#PROG="mpcs-i386-pc-linux4"
CAMNAME="Oscam Server_One"
# end
# This method starts Oscam
start_cam ()
{
/$FOLDER/$PROG -c . &
#/root/$FOLDER/$PROG -b &
sleep 5
}
# This method stops Oscam
stop_cam ()
{
killall -9 $PROG
}
case "$1" in
start)
echo "[SCRIPT] $1: $CAMNAME"
start_cam
;;
stop)
echo "[SCRIPT] $1: $CAMNAME"
stop_cam
;;
restart)
echo "Restarting $CAMNAME"
stop_cam
sleep 5
start_cam
;;
*)
"$0" stop
exit 1
;;
esac
exit 0

Then chmod 755 osc script
So basically the terminal commands for osc script are:

Code:
osc start # to start oscam
osc stop #to stop oscam
osc restart #to restart oscam

4- Now replace the code on the oscamtimeout.sh with following
Code:
#!/bin/bash
# accepable number of timeouts CAN'T BE LESS THAN THAT 2 "s client timeout=1000 ms, fallback timeout=700 ms, cache delay=0 ms"
SIZE="4"
# oscam init script
STARTSCRIPT="/usr/local/bin/osc"
# log file
LOG="/usr/local/bin/oscam.log"
CHECK="`tail -200 $LOG |grep -v grep |grep -c timeout`"
# If the the word "timeout" appears more times then SIZE ...
if [ '$CHECK' -gt '$SIZE' ]; then
# delete the log
rm "$LOG"
# logging restarts of oscam
echo 'oscam restarted becouse of timeot at' $(date '+%Y_%m_%d_%H:%M') >> /usr/local/bin/oscamtimeouts.log
#killing oscam
#kill -KILL $(pidof oscam)
"$STARTSCRIPT" stop
# wait 2 sec
sleep 2
# start oscam
"$STARTSCRIPT" start
else
echo 'nincs' > /dev/null
exit 1
fi

5- To set crontab from terminal:
Code:
crontab -e
and add the below line
Code:
*/5 * * * * /usr/local/bin/oscamtimeout.sh

Kind regards
 
Top