#!/bin/sh
# This script connects to all recent STBs, ignores any with "demo_unit" and changes the channel to #3

#######################################################################################
export TZ=Europe/London
port=5004
command_to_run="STBPLAYCH 3"
ignore_location="demo_unit"
#######################################################################################

STB_LIST=`tail -1000 /var/log/apache2/access.log | grep login | grep "location=" | grep -v "$ignore_location" | cut -f1 -d\  | sort -u`

#echo -e "Running [$command_to_run] on:\n$STB_LIST"
#######################################################################################

for host in $STB_LIST
do
( echo open ${host} 5004
sleep 2
echo "engineer\r"
sleep 4
echo "iptv250\r"
sleep 5
echo "${command_to_run}\r"
echo "exit\r"
sleep 2
) | ( /usr/bin/telnet ) &
sleep 1
done
