更新11#程序
update_11.sh
#!/bin/sh
failed_file_name='error.txt'
mycommand() {
(sleep 1; echo "root";
sleep 1; echo;
sleep 1; echo "cd /home/ftp;chmod +x update.sh;./update.sh $1 $2 $3 $4;exit";
sleep 1; )| telnet $2
}
get_10_ip() {
ip_11=`grep -m 1 'channel_ip' /usr/callsc_mtv/cfg/ch00.cfg | awk -F"=" '{print $2}'`
ip=`ifconfig eth0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`
if [ $ip ] && [ $report_error_ip ] && [ ${report_error_ip%%.*} -eq ${ip%%.*} ];then
ip_10=$ip
fi
if [ $ip ] && [ ${ip_11%%.*} -eq ${ip%%.*} ];then
receive_error_ip=$ip
fi
ip=`ifconfig eth0:0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`
if [ $ip ] && [ $report_error_ip ] && [ ${report_error_ip%%.*} -eq ${ip%%.*} ];then
ip_10=$ip
fi
if [ $ip ] && [ ${ip_11%%.*} -eq ${ip%%.*} ];then
receive_error_ip=$ip
fi
ip=`ifconfig eth0:1 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`
if [ $ip ] && [ $report_error_ip ] && [ ${report_error_ip%%.*} -eq ${ip%%.*} ];then
ip_10=$ip
fi
if [ $ip ] && [ ${ip_11%%.*} -eq ${ip%%.*} ];then
receive_error_ip=$ip
fi
ip=`ifconfig eth0:2 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`
if [ $ip ] && [ $report_error_ip ] && [ ${report_error_ip%%.*} -eq ${ip%%.*} ];then
ip_10=$ip
fi
if [ $ip ] && [ ${ip_11%%.*} -eq ${ip%%.*} ];then
receive_error_ip=$ip
fi
}
genarate_script() {
if [ -f update.sh ];then
rm update.sh
fi
echo "#!/bin/sh" >> update.sh
echo 'if [ $# -ne 4 ];then' >> update.sh
echo ' exit' >> update.sh >> update.sh
echo 'fi' >> update.sh
echo 'if [ ! -s $3 ];then' >> update.sh
echo ' printf "$s %s size is 0\n" $2 $3' >> update.sh
echo ' touch $2.failed' >> update.sh
echo ' if [ -f $2.failed ];then' >> update.sh
echo ' ftpput $1 $2.failed' >> update.sh
echo ' if [ $? -eq 0 ];then' >> update.sh
echo ' rm $2.failed' >> update.sh
echo ' fi' >> update.sh
echo ' else' >> update.sh
echo ' touch $2.failed' >> update.sh
echo ' fi' >> update.sh
echo " exit" >> update.sh
echo "fi" >> update.sh
#echo 'ls /opt/IptvEpg`date +%Y.%m.%d`* | xargs rm' >> update.sh
echo 'mv /opt/$3 /opt/$3$4' >> update.sh
echo 'mv /home/ftp/$3 /opt/$3' >> update.sh
echo 'chmod 777 /opt/$3' >> update.sh
echo 'pkill $3' >> update.sh
echo 'printf "%s update successful\n" $2' >> update.sh
echo 'exit' >> update.sh
}
parse_channels() {
pos=$(expr index "$1" '-')
if [ $pos != 0 ];then
let end_pos=pos-1
channel_num_start=${1%-*}
channel_num_end=${1#*-}
else
channel_num_start=$1
channel_num_end=$1
fi
}
myput() {
ftpput $1 update.sh
if [ $? -ne 0 ];then
return -1
fi
ftpput $1 $filename
if [ $? -ne 0 ];then
return -1
fi
return 0
}
update() {
for i in `seq $channel_num_start 1 $channel_num_end`
do
#echo "loop"
if [ $i -gt 9 ];then
channel_prefix="/usr/callsc_mtv/cfg/ch"
else
channel_prefix="/usr/callsc_mtv/cfg/ch0"
fi
dir=$channel_prefix$i$channel_suffix
echo $dir
if [ ! -f $dir ];then
break
fi
ip=`grep -m 1 'channel_ip' $dir | awk -F"=" '{print $2}'`
printf "begin update %s\n" $ip
ping -c 1 $ip 1>/dev/null 2>&1
#printf "file is = %s\n" $filename
if [ $? -eq 0 ];then
if [ ! -s $filename ];then
printf "update failed all channels %s %s size is 0\n" $ip_10 $filename >> $failed_file_name
printf "update failed all channels: %s size is 0 or not exist\n" $filename
break
fi
myput $ip
if [ $? -eq 0 ];then
#mycommand $receive_error_ip $ip $filename `date +%f`
mycommand $receive_error_ip $ip $filename `date +%F`
else
printf "ip [%s] channel [%d] [%s] ftpput failed\n" $ip_10 $i $ip >> $failed_file_name
printf "ip [%s] channel [%d] [%s] ftpput failed\n" $ip_10 $i $ip
fi
else
printf "ip [%s] channel [%d] [%s] ping failed\n" $ip_10 $i $ip >> $failed_file_name
printf "ip [%s] channel [%d] [%s] ping failed\n" $ip_10 $i $ip
fi
done
}
if [ $# -ge 2 ];then
if [ $# -eq 3 ];then
report_error_ip=$3
fi
filename=$2
parse_channels $1
elif [ $# -eq 1 ];then
echo "default program[local_player]"
filename="local_player"
parse_channels $1
elif [ $# -eq 0 ];then
echo "default channel[0-15] default program[local_player]"
channel_num_start=0
channel_num_end=15
filename="local_player"
fi
channel_suffix=".cfg"
if [ -f update.sh ];then
rm update.sh
fi
get_10_ip
genarate_script
update
ls | grep *fail | wc -l
if [ $? -gt 0 ];then
for f in `ls | grep failed`
do
cat $f >> $failed_file_name
rm $f
done
fi
if [ -s $failed_file_name ];then
echo
echo "-------errors-------"
cat $failed_file_name
echo "--------------------"
#printf "report_error_ip = %s ip_10 = %s\n" $report_error_ip $ip_10
if [ $report_error_ip ];then
mv $failed_file_name $ip_10.failed
if [ $report_error_ip != $ip_10 ];then
ftpput $report_error_ip $ip_10.failed
rm $ip_10.failed
fi
fi
fi
echo "update complete"
update_all.sh
#!/bin/sh
filename="local_player"
arr_size=0
arr_ip_size=0
failed_file_name='error.txt'
get_local_ip() {
ip=`ifconfig eth0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`
a=${ip%%.*}
#printf "a=%s local_ip_prefix=%s\n" $a $local_ip_prefix
if [ $ip ] && [ ${ip%%.*} -eq $local_ip_prefix ];then
local_ip=$ip
#printf "1:%s 11:%s\n" $local_ip_prefix $ip
return
fi
ip=`ifconfig eth0:0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`
if [ $ip ] && [ ${ip%%.*} -eq $local_ip_prefix ];then
local_ip=$ip
#printf "2:%s 11:%s\n" $local_ip_prefix $ip
return
fi
ip=`ifconfig eth0:1 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`
if [ $ip ] && [ ${ip%%.*} -eq $local_ip_prefix ];then
local_ip=$ip
#printf "3:%s 11:%s\n" $local_ip_prefix $ip
return
fi
ip=`ifconfig eth0:2 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`
if [ $ip ] && [ ${ip%%.*} -eq $local_ip_prefix ];then
local_ip=$ip
#printf "3:%s 11:%s\n" $local_ip_prefix $ip
return
fi
}
login() {
(sleep 1; echo "root";
sleep 1; echo "root";
sleep 1; echo "cd /home/ftp;chmod +x update_11.sh;./update_11.sh $2 $3 $5";
sleep $4; echo "exit";
sleep 1;) | telnet $1
}
myput() {
if [ ! -s $filename ] || [ ! -s update_11.sh ];then
printf "error: file %s or update_11.sh is not exist or size is 0\n" $filename
exit
fi
ftpput $1 update_11.sh
if [ $? -ne 0 ];then
echo "update_11.sh ftpput failed"
return 1
else
echo "update_11.sh ftpput success"
fi
ftpput $1 $filename
if [ $? -ne 0 ];then
printf "10#[%s] %s ftpput failed\n" $1 $filename
return 1
else
printf "10#[%s] %s ftpput success\n" $1 $filename
fi
return 0
}
mycommand() {
for i in `seq 0 $(($arr_ip_size-1))`
do
eval ip="\$arr_ip$i"
eval ch="\$arr_channel$i"
#echo $ip $ch
pos=$(expr index "$ch" '-')
if [ $pos -eq 0 ];then
tm=5
else
local start=${ch%-*}
local end=${ch#*-}
tm=$((($end-$start+1)*5))
fi
#printf "localip=%s ip=%s\n" $local_ip $ip
ping -c 1 $ip 1>/dev/null 2>&1
if [ $? -eq 0 ];then
if [ $local_ip != $ip ];then
myput $ip
fi
if [ $? -eq 0 ];then
#printf "%s %s %s %s" $ip $ch $filename $tm
login $ip $ch $filename $tm $local_ip
else
printf "10#[%s] ftpput failed\n" $ip >> $failed_file_name
fi
else
printf "10#[%s] ping failed\n" $ip >> $failed_file_name
fi
done
}
if [ $# -eq 0 ];then
echo "usage1: ./update_all ip1:0-7 ip2-ip3:1-7 ip4 local_player"
echo "usage2: ./update_all *.txt"
echo "172.16.0.55:0-7"
echo "172.16.0.56-58:0-7"
echo "172.16.0.51-53:5"
echo "172.16.0.51-53"
echo "local_player"
exit
fi
parse_ip() {
pos1=$(expr index "$1" '-')
if [ $pos1 -eq 0 ];then
eval arr_ip$arr_ip_size=$1
eval arr_channel$arr_ip_size=$2
let arr_ip_size+=1
#printf "single = %s %s\n" $1 $2
else
ip=$1
s=${ip%-*}
p=${s%.*}
start=${s##*.}
end=${ip#*-}
#printf "s=%s start =%s end=%s p=%s\n" $s $start $end $p
for index in `seq $start $end`
do
eval arr_ip$arr_ip_size=$p.$index
eval arr_channel$arr_ip_size=$2
#printf "multi=%s %s\n" $p.$index $2
let arr_ip_size+=1
done
fi
}
parse_one_arg() {
n=`echo $1 | awk -F"." '{print NF}'`
#printf "n=%d\n" $n
if [ $n -ne 4 ];then
#printf "filename is %s\n" $1
filename=$1
return
fi
local pos=$(expr index "$1" ':')
if [ $pos -eq 0 ];then
parse_ip $1 '0-15'
#printf "1=%s\n" $1
else
local ip=${1%:*}
local channel=${1#*:}
#printf "arg=%s ip=%s channel=%s\n" $1 $ip $channel
parse_ip $ip $channel
fi
}
parse_args() {
for arg in $*
do
parse_one_arg $arg
done
}
parse_args_from_file() {
while IFS= read -r line <&3; do
#printf "line = %s\n" $line
parse_one_arg $line
done 3< $1
}
if [ $# -eq 1 ] && [ ${1##*.} == "txt" ];then
tmp=`head -n 1 $1`
local_ip_prefix=${tmp%%.*}
printf "txt=%s\n" $1
parse_args_from_file $1
else
for i in $*
do
n=`echo $i | awk -F"." '{print NF}'`
if [ $n -eq 4 ];then
local_ip_prefix=${i%%.*}
else
filename=$i
fi
done
parse_args $*
fi
if [ ! -s $filename ] || [ ! -s ./update_11.sh ]; then
echo "--------------------------errors--------------------------------"
printf "%s or update_11.sh not exist or size is 0\n" $filename
echo "--------------------------errors--------------------------------"
exit
fi
get_local_ip
echo $local_ip
printf "-------------------------\n"
for i in `seq 0 $(($arr_ip_size-1))`
do
eval var="\$arr_ip$i"
eval var1="\$arr_channel$i"
printf "ip=%s ch=%s %s\n" $var $var1 $filename
done
printf "-------------------------\n"
mycommand
n=`ls | grep failed | wc -l`
if [ $n -gt 0 ];then
for f in `ls | grep failed`
do
cat $f >> $failed_file_name
rm $f
done
fi
echo
echo "all update complete..."
if [ -s $failed_file_name ];then
echo
echo "------------------------errors------------------------"
cat $failed_file_name
rm $failed_file_name
echo "------------------------errors------------------------"
fi
읽어보기
update_11.sh
功能:更新一块10号板上的部分或全部小板程序
用法: ./update_11.sh 0-7 local_player # [0-n:通道号,可以省略默认0-15 ] [local_player:可以省略或其他,默认local_player]
./update_11.sh
./update_11.sh 0-7
./update_11.sh 2 local_player #有程序名的话,通道号不可以省略
----------------------------------------------------------
update_all.sh
功能:更新全部10号板上的部分或全部小板程序(local_player或IptvEpg或其他) ,update_all.sh要调用update_11.sh
用法1:./update_all 172.17.0.51-58:2-5 172.17.0.52:2-5 local_player 172.17.0.53:2 172.17.0.54
用法2:./update_all.sh yidong.txt #*.txt 这个文件后缀必须是.txt, 名字随便命名。
#同把命令行内容写到*.txt中
yidong.txt
----------------
172.17.0.51-58:2-5 #ip范围:通道范围, ip可以是单个或多个连续的,通道号可以是单个或多个连续的也可以省略,默认0-15
172.17.0.52:2-5
local_player #要更新的程序名,可以写在任意一行,可以省略默认local_player
172.17.0.53:2
172.17.0.54
----------------------------------------------------------
复制上面两个脚本到/home/ftp
chmod 777 update_all.sh
eg升级中兴的采集程序:
1 ./update_all.sh zx.txt
zx.txt
-----------------
10.109.32.170:7
10.109.48.100:7
IptvEpg
10.109.80.170:7
-----------------
2 ./update_all.sh 10.109.32.170:7 IptvEpg 10.109.48.100:7 10.109.80.170:7
eg升级播控local_player
./update_all.sh 10.109.0.61-66
Reference
이 문제에 관하여(更新11#程序), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/moonxu0722/geng-xin-11cheng-xu-3j3g텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)