#!/bin/sh #bash >= 2.05b,sed >= 4.1 version=0.9.3-rc3 prog_version=menat-progchk.sh-$version LANG=C opt_str=$* . /var/menat/bin/menat-functions db_echo() { dvn=`expr "$debug" + 0 2>/dev/null`;dvn_v=$? if [ $dvn_v = 0 ]&&[ "$debug" = 1 ];then echo "$*" fi } db2_echo() { dvn=`expr "$debug" + 0 2>/dev/null`;dvn_v=$? if [ $dvn_v = 0 ]&&[ "$debug" -ge 3 ];then echo "$*" fi } ft_date() { if [ "$2" = 1 ];then f_ft=`find $1 -maxdepth 0 -follow -printf '%TY-%Tm-%Td %Ta %TH:%TM\n'`;f_v=$? else f_ft=`find $1 -maxdepth 0 -follow -printf '%TY%Tm%Td%TH%TM\n'`;f_v=$? fi if [ $f_v = 0 ];then echo $f_ft return 0 else return $f_v fi } n_ident() { if [ "$1" = 0 ];then dvn=0 dvn_v=0 else dvn=`expr "$1" + 0 2>/dev/null`;dvn_v=$? fi if [ $dvn_v = 0 ];then ni_v=$1 while [ ${ni_v:0:1} = 0 ]&&[ ${#ni_v} != 1 ];do ni_v=${ni_v#0} if [ ${#ni_v} = 1 ];then break fi done echo $ni_v return 0 else echo ${2:-unknown} return $dvn_v fi } wget_sh () { exec 5<>/dev/tcp/$4/80 echo -e "GET $5 HTTP/1.0" >&5 echo -e "Cookie: areaId=\"$3\"\n" >&5 nkf -Lue <&5 >$2 echo >>$2 } iepg_get_YmdHM() { iepg=$1 Y=`grep year: $iepg`;Y=${Y#* } m=`grep month: $iepg`;m=${m#* } d=`grep date: $iepg`;d=${d#* } HM=`grep start: $iepg`;HM=${HM#* };HM=${HM:0:2}${HM:3:2};HM=${HM#* } echo $Y$m$d$HM } stn_db="/usr/share/menat/iepg.db/STATION.ID" help_mesg="-i 番組開始時間を西暦月日時間の12桁で指定します。 -s ステーションIDを指定します。 -c ch.listの設定がある場合は、チャンネルナンバーでの指定も可能です。 -r デフォルトでは、文字コードeuc-jpに変換され出力されますが、-rが指定される と生のままのデータを出力します(おそらくshift_jisです)。 -d 番組探索を抑制します。 " exit_mesg="unknown or invalid option was given, aborted. $help_mesg" user_agent='Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729)' while [ "$1" ];do opt=$1 OPTARG=$2 case $opt in -v ) vs_hn=$OPTARG ;shift 2;; -i ) shift; start_t=$OPTARG ;shift ;; -l ) iepg_ch_ls=$OPTARG if [ ! -f "$iepg_ch_ls" ];then echo "$iepg_ch_ls is not found." >&2 exit 1 fi shift 2 ;; -c ) tmp_ch=$OPTARG ;shift 2;; -D ) debug=$OPTARG ;shift 2;; -n ) np_mode=$OPTARG ;shift 2;; -a ) all_ok=1 ;shift ;; -e ) exact_out=1;shift ;; -E ) prg_verbose=1;shift ;; -d ) de_mode=0;shift ;; -r ) exact_out2=1 ;shift ;; -s ) opt_st_cd=$OPTARG ;shift 2;; -u ) iepg_uri_id=$OPTARG ;uri_chk=1 ;shift 2;; -S ) iepg_span=$OPTARG ;shift 2;; -V ) prgchk_ver=1 ;shift ;; -N ) next_prog=1 ;shift ;; -h|-H ) echo "$help_mesg";exit 0 ;; * ) echo "${opt}, $exit_mesg" >&2;exit 1 ;; esac done if [ "$prgchk_ver" = 1 ];then echo $version exit 0 fi if [ "$de_mode" != 0 ];then de_mode=1 fi if [ "$uri_chk" = 1 ];then if [ "$iepg_uri_id" = 0 ];then iepg_href="http://tv.so-net.ne.jp/" db_echo "iEPG on テレビ王国" elif [ "$iepg_uri_id" = 1 ];then iepg_href="http://www.tvguide.or.jp/cgi-bin/iepg.pl" db_echo "iEPG on インターネットTVガイド" opt_uri1="-u 1" else echo "サポートされているiEPGサイトは、テレビ王国(0)、TVガイド(1)です。 menat-progchk -u [01] -i xxxxxxxxxxxx -s xxxxxx" >&2 exit 1 fi else iepg_uri_id=0 iepg_href="http://tv.so-net.ne.jp" action_cgi="/iepg.tvpi?id=" iepg_href_cgi=$iepg_href$action_cgi #http://tv.so-net.ne.jp/iepg.tvpi?id=101064200805222154 fi for t in -v -i -l -c -D -e -s ;do if [ $t = "$start_t" ];then start_t="" fi if [ $t = "$tmp_ch" ];then tmp_ch="" fi if [ $t = "$opt_st_cd" ];then opt_st_cd="" fi done for r in $opt_str ;do if [ $r = "-i" ];then opt_i=1 fi if [ $r = "-c" ];then opt_c=1 dvn=`n_ident $tmp_ch`;dvn_v=$? if [ $dvn_v != 0 ];then echo "ch number is invalid." >&2 exit 1 elif [ $tmp_ch -gt 63 ]||[ $tmp_ch -le 0 ];then echo "ch number is too large." >&2 exit 1 fi fi if [ $r = "-s" ];then if [ "$iepg_uri_id" = 0 ];then opt_s=1 dvn=`n_ident $opt_st_cd`;dvn_v=$? if [ $dvn_v != 0 ]||[ ${#opt_st_cd} != 8 ];then echo "station code $opt_st_cd is invalid." >&2 exit 1 fi elif [ "$iepg_uri_id" = 1 ];then opt_s=1 if [ ${#opt_st_cd} != 5 ];then echo "station code $opt_st_cd is invalid." >&2 exit 1 fi fi fi done if [ "$tmp_ch" ]&&[ "$opt_st_cd" ];then echo "ch option -c and st_cd -s can not coexist." >&2 exit 1 fi if [ "$start_t" ]&&[ ! "$tmp_ch" ]&&[ ! "$opt_st_cd" ];then echo "st_cd option -s or ch option -c is required." >&2 exit 1 elif { [ "$tmp_ch" ]||[ "$opt_st_cd" ]; }&&[ ! "$start_t" ];then if [ "$opt_i" = 1 ];then echo "start time value is null." >&2 else echo "start time option -i is required." >&2 fi exit 1 fi exe_hn=`hostname` user_h=/var/menat menat_bin=$user_h/bin menat_progchk=$menat_bin/menat-progchk.sh menat_sad=$menat_bin/menat-sad.sh menat_cr=$menat_bin/menat-cr.sh menat_sys_d=/etc/menat vs_ls=`cat $menat_sys_d/vs.list` iepg_span=$iepg_span opt0=`basename $0` db_echo "$opt0-$version starts." if [ "$vs_hn" ]&&[ -d $user_h/$vs_hn ]&&[ -w $user_h/$vs_hn ];then vs_name=$vs_hn vs_hn=${vs_name%%.*} vs_ls_ok=1 elif [ "$vs_hn" ]&&[ "$vs_ls" ];then for t in $vs_ls ;do if [ $vs_hn = ${t%%.*} ];then if [ -d $user_h/$t ];then if [ -d $user_h/$t/iepg ];then if [ -w $user_h/$t/iepg ]||[ "$start_t" ];then vs_name=$t vs_ls_ok=1 break else echo "$opt0-$version: $user_h/$t/iepg, permission denied." >&2 exit 1 fi else mkdir $user_h/$t/iepg;mkdir_v=$? if [ $mkdir_v = 0 ];then vs_name=$t vs_ls_ok=1 break else echo "$opt0-$version: can't creat $user_h/$t/iepg." >&2 exit 1 fi fi else echo "$opt0-$version: $user_h/$t is not found, vs.list error?" >&2 exit 1 fi fi done if [ "$vs_ls_ok" != 1 ];then echo "$opt0-$version: valid iepg directory is not found, vs.list error?" >&2 exit 1 fi else if [ -d $user_h/$exe_hn ];then if [ -d $user_h/$exe_hn/iepg ];then if [ -w $user_h/$exe_hn/iepg ]||[ "$start_t" ];then vs_name=$exe_hn vs_hn=${exe_hn%%.*} vs_ls_ok=1 else echo "$opt0-$version: $user_h/$exe_hn/iepg, permission denied." >&2 exit 1 fi else mkdir $user_h/$exe_hn/iepg;mkdir_v=$? if [ $mkdir_v = 0 ];then vs_name=$exe_hn vs_hn=${exe_hn%%.*} vs_ls_ok=1 else echo "$opt0-$version: can't creat $user_h/$exe_hn/iepg." >&2 exit 1 fi fi else echo "$opt0-$version: $user_h/$exe_hn is not found, vs.list error?" >&2 exit 1 fi fi vs_h=$user_h/$vs_name menat_h=$vs_h/menat menat_h_t=$menat_h/tmp ma_h=$vs_h/vfiles ma_h_t=$ma_h/tmp if [ "$start_t" ];then if [ -w $vs_h/iepg ];then menat_iepg=$vs_h/iepg elif [ -w $menat_h_t ];then menat_iepg=$menat_h_t else menat_iepg=/tmp fi if [ -w $menat_h/tmp/menat.log ];then menat_log=$menat_h/tmp/menat.log else menat_log=/dev/null fi st_ext=.$$ else menat_log=$menat_h/tmp/menat.log menat_iepg=$vs_h/iepg fi menat_iepg_ch=$vs_h/iepg/ch.list ch_list=$menat_iepg_ch menat_mail=$menat_bin/menat-mail.sh iepg_db_sony=/usr/share/menat/iepg.db/STATION.ID iepg_db_tvg=/usr/share/menat/iepg.db/STATION.ID.tvg n_YmdHM=`date '+%Y%m%d%H%M'` n1_YmdHM=`date -d '-1day' '+%Y%m%d%H%M'` n_Ymd=${n_YmdHM:0:8} n1_Ymd=${n1_YmdHM:0:8} if [ `id -un` = menat ];then if [ -f /var/menat/.menatrc ];then . /var/menat/.menatrc fi for t in `ls -d $menat_iepg/* 2>/dev/null` ;do if [ "$start_t" ]||[ "$debug" = 1 ];then break fi if [ -d "$t" ];then continue fi f_time=`ft_date $t 1` rm_YmdHM=`date -d "$f_time 14day" '+%Y%m%d%H%M'` db2_echo "if [ $rm_YmdHM '<' $n_YmdHM ];then" if [ -d $t ];then db2_echo "$t is directory." elif [ "`basename $t`" = ch.list ];then db2_echo "$t is not target." elif [ $rm_YmdHM '<' $n_YmdHM ];then db2_echo "time expired." rm -f $t else db2_echo "time does not expire." fi db2_echo done fi if [ "$np_mode" ];then chk_iepg_ls_0="$np_mode" for t in $chk_iepg_ls_0 ;do if [ -f $t ];then if [ ${t:0:1} = / ];then chk_iepg_ls="$chk_iepg_ls $t" else chk_iepg_ls="$chk_iepg_ls `pwd`/$t" fi continue else if [ -f $menat_h/$t ];then if [ "$chk_iepg_ls" ];then chk_iepg_ls="$chk_iepg_ls $menat_h/$t" else chk_iepg_ls="$menat_h/$t" fi continue else if [ "$debug" ];then db_echo $t, such file is not found. else echo $t, such file is not found. >&2 fi exit 1 fi fi done else chk_iepg_ls=`ls $menat_h/*.mtq 2>/dev/null` fi if [ "$start_t" ];then next_prog=${next_prog:-0} else next_prog=1 fi np_wget_err=0 for t in $start_t $chk_iepg_ls ;do title="";title_old="";title_new="";end_time="";end_time_old="";end_time_new="" extend=0;extend_new=0;extend_old=0;tr_YmdHM="";q_iepg="";err_mesg="";iepg_re_dd="" re_chk="";out_dd_v="";iepg_e2=0 if [ -d $t ];then continue fi tt=`basename $t` iepg_YmdHM=${tt%.*.mtq} dvn=`n_ident $iepg_YmdHM`;dvn_v=$? if [ ${#iepg_YmdHM} != 12 ]||[ $dvn_v != 0 ];then if [ "$start_t" ];then echo "$start_t is invalid mtq file." >&2 exit 1 else continue fi fi if [ ! "$start_t" ];then if [ $n_YmdHM '>' $iepg_YmdHM ];then continue fi if [ ! -f $t ];then cap_dev_n=`$t -c cap_dev|cut -c 11` if [ ${cap_dev_n:-0} = 0 ];then cdn="" else cdn=$cap_dev_n fi if [ -f $menat_h/$iepg_YmdHM.w$cdn.mtq ];then t=$menat_h/$iepg_YmdHM.w$cdn.mtq tt=$iepg_YmdHM.w$cdn.mtq prg_org_id=`$t -c org_id` prg_prs_id=`$t -c prs_id` prg_sr_id=`$t -c sr_id` if [ ! "$prg_prs_id" ];then e2_iepg_id=`$t -c bfn` else e2_iepg_id=$prg_prs_id fi else if [ ${tt:13:1} = n ];then echo "$tt is not registered program. execute menat_sad for $tt." >>$menat_log echo "$menat_sad -vs $vs_name $prog_version $tt" >>$menat_log $menat_sad -vs $vs_name $prog_version $tt if [ -f $menat_h/$iepg_YmdHM.w$cdn.mtq ];then t=$menat_h/$iepg_YmdHM.w$cdn.mtq tt=$iepg_YmdHM.w$cdn.mtq fi fi fi if [ ! -f $t ];then continue fi else prg_org_id=`$t -c org_id` prg_prs_id=`$t -c prs_id` prg_sr_id=`$t -c sr_id` if [ ! "$prg_prs_id" ];then e2_iepg_id=`$t -c bfn` else e2_iepg_id=$prg_prs_id fi fi fi if [ $iepg_YmdHM '>' `date -d ${iepg_span:-1month} '+%Y%m%d%H%M'` ];then if [ ! "$start_t" ];then db_echo "$tt is too far future program." db_echo continue fi fi iepg_Y=${iepg_YmdHM:0:4} iepg_m=${iepg_YmdHM:4:2} iepg_d=${iepg_YmdHM:6:2} iepg_H=${iepg_YmdHM:8:2} iepg_M=${iepg_YmdHM:10:2} iepg_Ymd=$iepg_Y$iepg_m$iepg_d iepg_HM=$iepg_H$iepg_M p_iepg_Ymd=$iepg_Y-$iepg_m-$iepg_d p_iepg_HM=$iepg_H:$iepg_M if [ "$start_t" ]&&[ "$tmp_ch" ];then ch=$tmp_ch elif [ ! "$opt_st_cd" ];then ch=`$t -c ch` if [ $ch = v ]||[ $ch = s ];then db_echo "$tt is $ch input enabled, not to use tuner." continue fi fi if [ "$start_t" ];then if [ "`date -d \"$iepg_Ymd $p_iepg_HM\" '+%Y%m%d%H%M' 2>/dev/null`" = "$start_t" ];then iepg_wHM=$iepg_YmdHM iepg_vv=0 else echo "$start_t is invalid time value." >&2 exit 1 fi else week_v=`$t -c week` if [ "$week_v" = w ];then iepg_w=`date -d $p_iepg_Ymd '+%w'` elif [ "$week_v" = d ]||[ "$week_v" = p ];then iepg_w=$week_v else iepg_w=$iepg_Ymd fi iepg_wHM=$iepg_w$iepg_H$iepg_M iepg_pch=`$t -c pch` cap_dev=`$t -c cap_dev` cap_dev_n=${cap_dev#/dev/video} case "$cap_dev_n" in [1-3] ) cap_dev_ext=.$cap_dev_n ;; * ) cap_dev_ext="" ;; esac st_nn=`grep -n ^# $t|head -n1`;st_nn=${st_nn%%:*} ln_eof=`cat $t|wc -l` ed_nn=$(($st_nn+1)) while [ $ed_nn -lt $ln_eof ];do edl_v=`sed -n "${ed_nn}p" $t|grep -c ^\#` if [ $edl_v = 0 ];then ed_nn=$(($ed_nn-1)) break else ed_nn=$(($ed_nn+1)) fi done tt_iepg_dd=`sed -n "${st_nn},${ed_nn}p" $t|grep -v "^\#!/bin/sh"` if [ `echo "$tt_iepg_dd"|grep -c ^\#program-title:` = 0 ];then db_echo "$tt has no iepg data." db_echo if [ "$week_v" = w ];then iepg_w=`date -d $p_iepg_Ymd '+%w'` elif [ "$week_v" = d ]||[ "$week_v" = p ];then iepg_w=$week_v else iepg_w=$iepg_Ymd fi iepg_wHM=$iepg_w$iepg_H$iepg_M if [ "$ch" ];then ch_ext=.${ch}ch fi iepg_new=$menat_iepg/$iepg_wHM$ch_ext.new$cap_dev_ext if [ -f $iepg_new ];then db_echo "found iepg_new=$iepg_new." tr_Y=`grep ^year: $iepg_new|cut -d' ' -f2` tr_m=`grep ^month: $iepg_new|cut -d' ' -f2` tr_d=`grep ^date: $iepg_new|cut -d' ' -f2` if [ "$tr_Y$tr_m$tr_d" = $iepg_Ymd ];then p_tr_HM=`grep ^start: $iepg_new|cut -d' ' -f2` tr_Ymd=$tr_Y$tr_m$tr_d tr_HM=`echo $p_tr_HM|sed 's/://'` tr_YmdHM=$tr_Ymd$tr_HM p_tr_Ymd=$tr_Y-$tr_m-$tr_d re_chk=1 elif [ ! "$tr_Y" ]||[ ! "$tr_m" ]||[ ! "$tr_d" ];then iepg_old_xx=1 out_dd_v=1 re_chk=0 else db_echo "but, ${iepg_new##*/} is too old." re_chk=0 out_dd_v=1 iepg_old_xx=1 fi else re_chk=0 fi if [ $re_chk = 0 ];then if [ ! -f $iepg_new ];then db_echo "not found iepg_new=$iepg_new." fi dvn=`n_ident $ch`;dvn_v=$? if [ $dvn_v = 0 ];then $menat_progchk $opt_uri1 -i $iepg_YmdHM -c $ch 2>/dev/null >$menat_iepg/tmp_new ;re_chk_v=$? else re_chk_v=125 fi if [ $re_chk_v = 0 ];then db_echo "get iepg_new=tmp_new." re_chk=1 elif [ $re_chk_v = 125 ];then db_echo "$ch is out of iepg." re_chk=1 else db_echo "get iepg_new failed." re_chk=0 fi fi iepg_vv=0 else iepg_st_str=`echo "$tt_iepg_dd"|grep $p_iepg_Ymd|grep $p_iepg_HM|head -n1` iepg_t_vv=`$t -c iepg_err` if [ "$iepg_st_str" ]&&[ ${iepg_t_vv:--3} -ge 0 ];then iepg_st_org=`echo $iepg_st_str|cut -d' ' -f3` iepg_et_org=`echo $iepg_st_str|cut -d' ' -f5` if [ ${#iepg_st_org} = 5 ];then db_echo "$tt has iepg data." db_echo else db_echo "$tt has no just start time." db_echo p_tr_HM=${iepg_st_org#*\(} p_tr_HM_e=${iepg_et_org#*\(} p_tr_HM=${p_tr_HM%\)*} tr_HM=`echo $p_tr_HM|sed 's/://'` if [ "$iepg_et_org" != "$p_tr_HM_e" ];then p_tr_HM_e=${p_tr_HM_e%\)*} tr_HM_e=`echo $p_tr_HM_e|sed 's/://'` else p_tr_HM_e="" tr_HM_e="" fi time_e=`$t -c time_e` time_s=`$t -c time_s` if [ 1$tr_HM '>' 1$iepg_HM ];then if [ $iepg_Ymd$tr_HM '>' $time_e ];then tr_YmdHM=`date -d "-1day $p_iepg_Ymd $p_tr_HM" '+%Y%m%d%H%M'` tr_Ymd=${tr_YmdHM:0:8} if [ "$tr_HM_e" ];then if [ 1$tr_HM '>' 1$tr_HM_e ];then tr_e_YmdHM=$iepg_Ymd$tr_HM_e else tr_e_YmdHM=$tr_Ymd$tr_HM_e fi else tr_e_YmdHM=$time_e fi else tr_YmdHM=$iepg_Ymd$tr_HM if [ "$tr_HM_e" ];then if [ 1$tr_HM '>' 1$tr_HM_e ];then tr_e_YmdHM=`date -d "1day $iepg_Ymd $p_tr_HM_e" '+%Y%m%d%H%M'` else tr_e_YmdHM=$iepg_Ymd$tr_HM_e fi else tr_e_YmdHM=$time_e fi fi else tr_YmdHM_1d=`date -d "1day $p_iepg_Ymd $p_tr_HM" '+%Y%m%d%H%M'` tr_Ymd_1d=${tr_YmdHM_1d:0:8} if [ $tr_YmdHM_1d '<' $time_e ];then tr_YmdHM=$tr_YmdHM_1d if [ "$tr_HM_e" ];then if [ 1$tr_HM '>' 1$tr_HM_e ];then tr_e_YmdHM=$tr_Ymd_1d$tr_HM_e else tr_e_YmdHM=$iepg_Ymd$tr_HM_e fi else tr_e_YmdHM=$time_e fi else tr_YmdHM=$iepg_Ymd$tr_HM if [ "$tr_HM_e" ];then if [ 1$tr_HM '>' 1$tr_HM_e ];then tr_e_YmdHM=$tr_Ymd_1d$tr_HM_e else tr_e_YmdHM=$iepg_Ymd$tr_HM_e fi else tr_e_YmdHM=$time_e fi fi fi if [ $time_s '>' $tr_e_YmdHM ]||[ $time_e '<' $tr_YmdHM ];then tr_YmdHM=$iepg_YmdHM tr_HM=$iepg_HM fi tr_Y=${tr_YmdHM:0:4} tr_m=${tr_YmdHM:4:2} tr_d=${tr_YmdHM:6:2} tr_Ymd=$tr_Y$tr_m$tr_d p_tr_Ymd=$tr_Y-$tr_m-$tr_d fi iepg_vv=1 else db_echo "$tt has no iepg data." db_echo iepg_vv=0 fi fi fi if [ ! "$opt_st_cd" ];then if [ "$iepg_ch_ls" ]&&[ -f "$iepg_ch_ls" ];then st_cd=`grep ch$ch $iepg_ch_ls|head -n1|cut -d':' -f3` pref_id_p=`grep ch$ch $iepg_ch_ls|head -n1|cut -d':' -f4` db_echo "specified ch.list $iepg_ch_ls is used." elif [ -f $menat_iepg_ch ];then if [ "$iepg_uri_id" = 1 ];then db_echo "ch.list for TVガイド is used." if [ -f $iepg_db_tvg ];then st_cd_sony=`grep ch$ch $menat_iepg_ch|head -n1|cut -d':' -f3` web_stn_sony=`grep ch$ch $menat_iepg_ch|head -n1|cut -d':' -f2` if [ `echo $web_stn_sony|grep -c '教育$'` != 0 ];then st_cd=Z0051 else st_cd_uri_org=`grep $st_cd_sony $iepg_db_sony|cut -d'#' -f1|grep -v '='` st_cd_uri=`echo "$st_cd_uri_org"|head -n1|cut -d':' -f6` st_cd_uri="http://$st_cd_uri/" st_cd=`grep -e "$st_cd_uri" $iepg_db_tvg|cut -d'#' -f1|head -n1|cut -d' ' -f2` fi else echo "iEPGサイト TVガイドでは、-cオプションは未対応です。" >&2 exit 1 fi else db_echo "ch.list $menat_iepg_ch is used." st_cd=`grep ch$ch $menat_iepg_ch|head -n1|cut -d':' -f3` pref_id_p=`grep ch$ch $menat_iepg_ch|head -n1|cut -d':' -f4` fi else db_echo "internal ch.list is used." prg_pref_id=23 case $ch in 1 ) st_cd=101024 ;; 2 ) st_cd= ;; 3 ) st_cd=101032 ;; 4 ) st_cd=101040 ;; 5 ) st_cd= ;; 6 ) st_cd=101048 ;; 8 ) st_cd=101056 ;; 10 ) st_cd=101064 ;; 12 ) st_cd=101072 ;; 14 ) st_cd=123608 ;; * ) if [ "$start_t" ];then db_echo "channel value $ch is invalid." >&2 exit 1 else continue fi ;; esac fi else st_cd=${opt_st_cd:0:6} pref_id_p=${opt_st_cd:6:2} fi if [ ! "$st_cd" ];then if [ "$start_t" ];then echo "st_cd value is invalid or null." >&2 exit 1 else db_echo "st_cd value is invalid or null." continue fi elif [ "$ch" ];then ch_ext=.${ch}ch elif [ -f $menat_iepg_ch ];then t_ch=`grep "^$st_cd " $menat_iepg_ch|head -n1|cut -d':' -f1` if [ "$t_ch" ];then ch_ext=.${t_ch}ch fi fi iepg_new=$menat_iepg/$iepg_wHM$ch_ext.new$st_ext$cap_dev_ext iepg_old=$menat_iepg/$iepg_wHM$ch_ext.old$st_ext$cap_dev_ext iepg_tmp=$menat_iepg/$iepg_wHM$ch_ext.tmp$st_ext$cap_dev_ext iepg_raw=$menat_iepg/$iepg_wHM$ch_ext.raw$st_ext$cap_dev_ext iepg_err=$menat_iepg/$iepg_wHM$ch_ext.err$st_ext$cap_dev_ext iepg_mesg=$menat_iepg/$iepg_wHM$ch_ext.mesg$st_ext$cap_dev_ext if [ "$start_t" ];then chk=0 old_ex=0 elif [ -f $iepg_new ];then ch_rex=`grep 'station: ' $iepg_new|head -n1` if [ `grep -c "$ch_rex" $t` != 0 ];then mv -f $iepg_new $iepg_old db_echo "mv -f $iepg_new $iepg_old" chk=1 old_ex=1 else rm -f $menat_iepg/$iepg_wHM.*$st_ext* old_ex=0 if [ $iepg_vv = 1 ];then chk=1 else chk=0 fi fi else old_ex=0 if [ $iepg_vv = 1 ];then chk=1 else chk=0 fi fi if [ "$tr_YmdHM" ];then wget_Ymd=$tr_Ymd wget_HM=$tr_HM p_wget_Ymd=$p_tr_Ymd p_wget_HM=$p_tr_HM else wget_Ymd=$iepg_Ymd wget_HM=$iepg_HM p_wget_Ymd=$p_iepg_Ymd p_wget_HM=$p_iepg_HM fi if [ "$iepg_uri_id" = 0 ];then iepg_qs="${iepg_href_cgi}$st_cd$wget_Ymd$wget_HM" elif [ "$iepg_uri_id" = 1 ];then iepg_qs="${iepg_href_cgi}?station=$st_cd&airdate=$wget_Ymd&airtime=$wget_HM" else iepg_qs="${iepg_href_cgi}$st_cd$wget_Ymd$wget_HM" fi wget --user-agent="$user_agent" -O $iepg_tmp "$iepg_qs" 2>/dev/null;wget_v=$? db_echo "wget -O $iepg_tmp \"$iepg_qs\" 2>/dev/null;wget_v=$wget_v" dvn=`chmod -f 664 $iepg_tmp` if [ $wget_v != 0 ];then echo >>$menat_log echo "menat-progchk.sh-$version: wget iepg file for $tt was failed." >>$menat_log db_echo "menat-progchk.sh-$version: wget iepg file for $tt was failed." wget_err_v=1 else nkf -Lue $iepg_tmp |grep -v ^\$ >$iepg_new dvn=`chmod -f 664 $iepg_new` if [ `grep -i -c '/dev/null >$iepg_tmp.rg;re_get_iepg=$? if [ $re_get_iepg = 0 ];then mv -f $iepg_tmp.rg $iepg_tmp nkf -Lue $iepg_tmp |grep -v ^\$ >$iepg_new iepg_Y_e1=`grep ^year: $iepg_new|cut -d' ' -f2` iepg_m_e1=`grep ^month: $iepg_new |cut -d' ' -f2` iepg_d_e1=`grep ^date: $iepg_new |cut -d' ' -f2` iepg_psHM_e1=`grep ^start: $iepg_new|cut -d' ' -f2` iepg_peHM_e1=`grep ^end: $iepg_new|cut -d' ' -f2` iepg_sHM_e1=`echo $iepg_psHM_e1|sed 's/://'` iepg_eHM_e1=`echo $iepg_peHM_e1|sed 's/://'` iepg_sYmd_e1=$iepg_Y_e1$iepg_m_e1$iepg_d_e1 iepg_sYmdHM_e1=$iepg_Y_e1$iepg_m_e1$iepg_d_e1$iepg_sHM_e1 iepg_psYmdHM_e1="$iepg_Y_e1-$iepg_m_e1-$iepg_d_e1 $iepg_psHM_e1" p_st_YmdaHM=`date -d "$iepg_Ymd $p_iepg_HM" '+%Y-%m-%d %a %H:%M'` ma_time_e=`$t -c time_e` ma_et_H=${ma_time_e:8:2} ma_et_M=${ma_time_e:10:2} p_ma_et_HM=$ma_et_H:$ma_et_M if [ $iepg_sYmdHM_e1 '<' $ma_time_e ];then iepg_err_v=0 iepg_re_tail1=`grep -v ': ' $iepg_new|tail -n1` iepg_re_stn=`grep ^station: $iepg_new` iepg_re_ttl=`grep ^program-title: $iepg_new` iepg_re_st=`grep ^start: $iepg_new|cut -d' ' -f2` iepg_re_et=`grep ^end: $iepg_new|cut -d' ' -f2` iepg_re_sb_ttl=`grep ^program-subtitle: $iepg_new` iepg_re_ext=`grep ^Extend: $iepg_new` iepg_re_ext_v=`grep ^Extend: $iepg_new|cut -d' ' -f2` iepg_opt_str=`echo $iepg_re_tail1|sed 's/」/」 /g;s/「/ 「/g;s/(終)/ (終) /g'` iepg_re_dsp=`grep ^description: $iepg_new` iepg_re_pfm=`grep ^performer: $iepg_new` if [ $iepg_HM != $iepg_sHM_e1 ];then p_st_YmdaHM="$p_st_YmdaHM($iepg_psHM_e1)" fi org_bfn=`$t -c bfn` org_opt1=`$t -c opt1` if [ "$org_opt1" ];then re_name="$org_bfn:$org_opt1" else re_name=$org_bfn fi if [ ${ma_time_e:8:4} != $iepg_eHM_e1 ];then iepg_re_dd="#$p_st_YmdaHM - $p_ma_et_HM($iepg_peHM_e1) ${ch}ch $re_name" else iepg_re_dd="#$p_st_YmdaHM - $p_ma_et_HM ${ch}ch $re_name" fi iepg_re_opt="" ext_str_fin="" for t2 in $iepg_opt_str ;do case $t2 in 「S」 ) iepg_re_opt="$iepg_re_opt STEREO" ;; 「字」 ) iepg_re_opt="$iepg_re_opt 文字多重" ;; 「E」 ) iepg_re_opt="$iepg_re_opt 二ヵ国語" ;; 「再」 ) iepg_re_opt="$iepg_re_opt 再放送" ;; 「N」 ) iepg_re_opt="$iepg_re_opt NEWS" ;; 「多」 ) iepg_re_opt="$iepg_re_opt 音声多重" ;; 「新」 ) iepg_re_opt="$iepg_re_opt 新番組" ;; 「天」 ) iepg_re_opt="$iepg_re_opt 天気予報" ;; (終) | 「終」 ) iepg_re_opt="$iepg_re_opt 最終回" ;; * ) ext_str_fin="$ext_str_fin $t2" ;; esac done iepg_ln=${iepg_ln:-80} iepg_re_dd="$iepg_re_dd #$iepg_re_stn #$iepg_re_ttl" if [ "$iepg_re_sb_ttl" ];then iepg_re_dd="$iepg_re_dd `echo $iepg_re_sb_ttl|nkf -ef$iepg_ln |sed 's/^/#/'`" fi if [ ${iepg_re_ext_v:-0} != 0 ];then iepg_re_dd="$iepg_re_dd #$iepg_re_ext" fi if [ "$iepg_re_dsp" ];then iepg_re_dd="$iepg_re_dd `echo $iepg_re_dsp |nkf -ef$iepg_ln |sed 's/^/#/'`" fi if [ "$iepg_re_pfm" ];then iepg_re_dd="$iepg_re_dd `echo $iepg_re_pfm |nkf -ef$iepg_ln |sed 's/^/#/'`" fi if [ "$iepg_re_opt" ];then iepg_re_dd="$iepg_re_dd #$iepg_re_opt" fi if [ "$iepg_re_tail1" ]&&[ "$ext_str_fin" ];then iepg_re_dd="$iepg_re_dd `echo ${ext_str_fin# } |nkf -ef$iepg_ln |sed 's/^/#/'`" fi else mv -f $iepg_new $iepg_err iepg_err_v=1 fi else rm -f $iepg_tmp.re_get iepg_err_v=1 fi fi else iepg_err_v=0 if [ ! "$start_t" ];then if [ $chk = 0 ];then re_chk=1 else chk=1 fi fi fi wget_err_v=0 fi if [ $wget_err_v = 1 ];then if [ "$start_t" ];then db_echo "menat-progchk.sh-$version failed to execute wget." exit 1 else err_mesg="menat-progchk.sh-$version failed to execute wget for ${t##*/}." fi np_wget_err=1 wget_err_t="$wget_err_t ${t##*/}" iepg_e2=1 elif [ $iepg_err_v = 1 ]&&[ ! "$start_t" ];then if [ $old_ex = 0 ];then title=`echo "$tt_iepg_dd"|grep ^\#program-title:`;title=${title#* } end_time=`grep "^\#$p_iepg_Ymd " $t|grep $p_iepg_HM|head -n1|sed 's/ 翌//'|cut -d' ' -f5` end_time=${end_time#*\(} end_time=${end_time%\)} extend=`echo "$tt_iepg_dd"|grep "^\#Extend:"|cut -d' ' -f2` extend=${extend:-0} else title_old="`grep ^\#program-title: $iepg_old|head -n1`";title=${title#* } end_time_old=`grep "^\#$p_iepg_Ymd " $iepg_old|grep $p_iepg_HM|head -n1|sed 's/ 翌//'|cut -d' ' -f5` end_time_old=${end_time_old#*\(} end_time_old=${end_time_old%\)} extend_old=`grep "^\#Extend:" $iepg_old|head -n1|cut -d' ' -f2` extend_old=${extend_old:-0} if [ $iepg_vv = 1 ];then title=`echo "$tt_iepg_dd"|grep ^\#program-title:`;title=${title#* } end_time=`grep "^\#$p_iepg_Ymd " $t|grep $p_iepg_HM|head -n1|sed 's/ 翌//'|cut -d' ' -f5` end_time=${end_time#*\(} end_time=${end_time%\)} extend=`echo "$tt_iepg_dd"|grep "^\#Extend:"|cut -d' ' -f2` extend=${extend:-0} fi fi err_mesg="menat-progchk.sh-$version can't get valid iepg file. the program time may be shifted?" iepg_e2=2 else if [ $chk = 0 ]||[ ${re_chk:-0} = 1 ];then if [ "$start_t" ];then if [ -f $iepg_new ];then web_exp=`grep $st_cd $stn_db|head -n1|cut -d':' -f4` if [ "$web_exp" ]&&[ "$exact_out" != 1 ];then web_exp=`grep $st_cd $stn_db|head -n1|cut -d':' -f1` ed -s $iepg_new >/dev/null 2>&1 </dev/null;wg_v1_0=$? wget --user-agent="$user_agent" -O $pref_html.1 "$wget_href2" 2>/dev/null;wg_v1_1=$? echo " wget -O $pref_html.0 \"$wget_href\" 2>/dev/null;wg_v1_0=$? wget -O $pref_html.1 \"$wget_href2\" 2>/dev/null;wg_v1_1=$? " cat $pref_html.0 $pref_html.1 >$pref_html db_echo "$pref_html \"$tt_href\" 2>/dev/null;wg_v1_0=$wg_v1_0;wg_v1_1=$wg_v1_1" if [ $wg_v1_0 != 0 ];then re_err=1 re_wg_err=1 break fi nkf -Lue $pref_html|sed 's/\n//g;s//a>\n/g'|grep iepg.tvpi|grep $st_cd|cut -d'=' -f5|cut -d'"' -f1 >$tmp_out.0 tmp_out_YmdHM=$st_cd$iepg_Ymd$iepg_HM echo $tmp_out_YmdHM >>$tmp_out.0 sort $tmp_out.0 >$tmp_out.1 #cp $tmp_out.1 /tmp/tt.db re_p0_YmdHMS=`grep -B 1 $tmp_out_YmdHM $tmp_out.1|head -n1` re_p0_Ymd=${re_p0_YmdHMS:6:8} re_p0_HM=${re_p0_YmdHMS:14:4} re_a0_YmdHMS=`grep -A 1 $tmp_out_YmdHM $tmp_out.1|tail -n1` re_a0_Ymd=${re_a0_YmdHMS:6:8} re_a0_HM=${re_a0_YmdHMS:14:4} if [ $re_p0_YmdHMS = $tmp_out_YmdHM ];then if [ $h_i = 1 ];then re_err=1 break fi h_i2=$(($h_i-1)) h_i2_dr="-12" elif [ $re_a0_YmdHMS = $tmp_out_YmdHM ];then if [ $h_i = 8 ];then h_i2=0 else h_i2=$(($h_i+1)) h_i2_dr="12" fi else h_i2=0 fi if [ $h_i2 != 0 ];then #http://tv.so-net.ne.jp/chart/23.action tt_head=`date -d "${h_i2_dr}hour ${iepg_Ymd} ${iepg_H}00" '+%Y%m%d%H%M'` tt_head2=`date -d "$((${h_i2_dr}+24))hour ${iepg_Ymd} ${iepg_H}00" '+%Y%m%d%H%M'` tt_href="/chart/${pref_id}.action?head=$tt_head" tt_href2="/chart/${pref_id}.action?head=$tt_head2" tt_host="tv.so-net.ne.jp" wget_kkk="http://$tt_host$tt_href&span=24" wget_rrr="http://$tt_host$tt_href2&span=24" href_wg_v2a="$tt_href/${h_i2}_$pref_id.html" wget --user-agent="$user_agent" -O $pref_html.0 "$wget_kkk" 2>/dev/null;wg_v2a=$? wget --user-agent="$user_agent" -O $pref_html.1 "$wget_rrr" 2>/dev/null;wg_v2b=$? cat $pref_html.0 $pref_html.1 >$pref_html db_echo "wget_sh -O $pref_html.0 $pref_id_p $tt_host \"${tt_href}index=0\" 2>/dev/null;wg_v2a=$wg_v2a" db_echo "wget_sh -O $pref_html.1 $pref_id_p $tt_host \"${tt_href}index=1\" 2>/dev/null;wg_v2a=$wg_v2b" if [ $wg_v2a != 0 ];then re_err=1 re_wg_err=2 break fi #cgi trigger changed from iepg.action to iepg.tvpi at 20070410 nkf -Lue $pref_html|sed 's/\n//g;s//a>\n/g'|grep iepg.tvpi|grep $st_cd|cut -d'=' -f5|cut -d'"' -f1 >$tmp_out.r0 tmp_out_YmdHM=$st_cd$iepg_Ymd$iepg_HM echo $tmp_out_YmdHM >>$tmp_out.r0 sort $tmp_out.r0 >$tmp_out.t1 prog_pt=$tmp_out.t1 else prog_pt=$tmp_out.1 re_err=0 fi if [ "$debug" ];then cp $prog_pt $tmp_out.ppt fi re_p1_YmdHMS=`grep -B 1 $tmp_out_YmdHM $prog_pt|head -n1` re_p1_Ymd=${re_p1_YmdHMS:6:8} re_p1_HM=${re_p1_YmdHMS:14:4} nx_p1_YmdHMS=`grep -A 1 $tmp_out_YmdHM $prog_pt|tail -n1` iepg_qs="${iepg_href_cgi}$re_p1_YmdHMS" wget --user-agent="$user_agent" -O $iepg_tmp.re "$iepg_qs" 2>/dev/null;wg_v2=$? db_echo "wget -O $iepg_tmp.re \"$iepg_qs\";wg_v2=$wg_v2" chmod -f 666 $iepg_tmp.re nkf -Lue $iepg_tmp.re |grep -v ^\$ >$iepg_new.re chmod -f 666 $iepg_new.re if [ `grep -c -i '' 1$re_ed_HM ];then re_ed_Ymd=`date -d "1day $re_ed_Ymd" '+%Y%m%d'` fi re_ed_YmdHM=$re_ed_Ymd$re_ed_HM if [ $iepg_YmdHM '>' $re_ed_YmdHM ];then db_echo "this program will end at $re_ed_YmdHM before $iepg_YmdHM." if [ $next_prog = 1 ];then re_p1_YmdHMS=`grep -A 1 $tmp_out_YmdHM $prog_pt|tail -n1` re_p1_Ymd=${re_p1_YmdHMS:6:8} re_p1_HM=${re_p1_YmdHMS:14:4} iepg_qs="${iepg_href_cgi}$re_p1_YmdHMS" wget --user-agent="$user_agent" -O $iepg_tmp.re "$iepg_qs" 2>/dev/null;wg_v3=$? db_echo "wget -O $iepg_tmp.re \"$iepg_href$iepg_qs\" 2>/dev/null;wg_v3=$wg_v3" if [ $wg_v3 != 0 ];then re_err=1 re_wg_err=3 break fi chmod -f 666 $iepg_tmp.re nkf -Lue $iepg_tmp.re |grep -v ^\$ >$iepg_new.re chmod -f 666 $iepg_new.re if [ `grep -c -i '/dev/null;wg_v4=$? db_echo "wget -O $iepg_tmp.re \"$iepg_href$iepg_qs\" 2>/dev/null;wg_v4=$wg_v4" if [ $wg_v4 != 0 ];then re_err=1 re_wg_err=4 break fi chmod -f 666 $iepg_tmp.re nkf -Lue $iepg_tmp.re |grep -v ^\$ >$iepg_new.re chmod -f 666 $iepg_new.re if [ `grep -c -i '' $tmp_out_YmdHM ];then end_err=1 else re_err=1 fi else end_err=0 fi break else end_err=0 break fi done else de_mode=0 out_date_err=1 tmp_out=save-$$ fi if [ "$de_mode" = 1 ];then if [ "$exact_out2" = 1 ];then cat $iepg_tmp.re elif [ "$all_ok" = 1 ]&&[ -f $iepg_new.re ];then cat $iepg_new.re elif [ "$end_err" = 1 ];then echo "no program." >&2 if [ ! "$debug" ];then rm -f $menat_iepg/[12345678]_[01234][0-9].html rm -f $menat_iepg/prog_tt* rm -f $menat_iepg/$iepg_wHM.*$st_ext rm -f $menat_iepg/$iepg_wHM.*.re else chmod -f 666 $menat_iepg/[12345678]_[01234][0-9].html chmod -f 666 $menat_iepg/prog_tt* chmod -f 666 $menat_iepg/$iepg_wHM.*$st_ext* fi exit 1 elif [ "$re_err" = 1 ];then if [ "$re_wg_err" ];then echo "retry wget $re_wg_err failed." >&2 else echo "retry failed." >&2 fi if [ ! "$debug" ];then rm -f $menat_iepg/[12345678]_[01234][0-9].html rm -f $menat_iepg/prog_tt* rm -f $menat_iepg/$iepg_wHM.*$st_ext rm -f $menat_iepg/$iepg_wHM.*.re else chmod -f 666 $menat_iepg/[12345678]_[01234][0-9].html chmod -f 666 $menat_iepg/prog_tt* chmod -f 666 $menat_iepg/$iepg_wHM.*$st_ext* fi exit 1 else web_exp=`grep $st_cd $stn_db|cut -d':' -f4` if [ "$web_exp" ]&&[ "$exact_out" != 1 ];then web_exp=`grep $st_cd $stn_db|cut -d':' -f1` ed -s $iepg_new.re >/dev/null 2>&1 <&2 fi echo "$err_mesg" >&2 exit 1 else rm -f $menat_iepg/[12345678]_[01234][0-9].html rm -f $menat_iepg/prog_tt* rm -f $menat_iepg/$iepg_wHM.*$st_ext rm -f $menat_iepg/$iepg_wHM.*.re echo "unknown error occured." >&2 exit 1 fi else if [ -f $iepg_new ];then chk_user=`$t -c menat_user` if [ -f /home/$chk_user/.menatrc ];then prog_reget=`. /home/$chk_user/.menatrc;echo $prog_reget` fi if [ "$prog_reget" = 1 ];then prog_reget_ok=1 fi db_echo "$tt was out of iEPG data check. but could get valid iepg file, why? " db_echo q_iepg=1 err_mesg="$tt was out of iEPG data check. but could get valid iepg file, why? " iepg_q_tail1=`grep -v ': ' $iepg_new|tail -n1` iepg_q_stn=`grep ^station: $iepg_new` iepg_q_ttl=`grep ^program-title: $iepg_new` iepg_q_st=`grep ^start: $iepg_new|cut -d' ' -f2` iepg_q_Y=`grep ^year: $iepg_new|cut -d' ' -f2` iepg_q_m=`grep ^month: $iepg_new|cut -d' ' -f2` iepg_q_d=`grep ^date: $iepg_new|cut -d' ' -f2` iepg_q_et=`grep ^end: $iepg_new|cut -d' ' -f2` iepg_q_sb_ttl=`grep ^program-subtitle: $iepg_new` iepg_q_ext=`grep ^Extend: $iepg_new` iepg_q_ext_v=`grep ^Extend: $iepg_new|cut -d' ' -f2` iepg_q_pYmdHM="$iepg_q_st $iepg_q_Y-$iepg_q_m-$iepg_q_d" iepg_q_pYmdaHM=`date -d "$iepg_q_pYmdHM" '+%Y-%m-%d %a %H:%M'` iepg_opt_str=`echo $iepg_q_tail1|sed 's/」/」 /g;s/「/ 「/g;s/(終)/ (終) /g'` iepg_q_dsp=`grep ^description: $iepg_new` iepg_q_pfm=`grep ^performer: $iepg_new` iepg_q_opt="" ext_str_fin="" for t2 in $iepg_opt_str ;do case $t2 in 「S」 ) iepg_q_opt="$iepg_q_opt STEREO" ;; 「字」 ) iepg_q_opt="$iepg_q_opt 文字多重" ;; 「E」 ) iepg_q_opt="$iepg_q_opt 二ヵ国語" ;; 「再」 ) iepg_q_opt="$iepg_q_opt 再放送" ;; 「N」 ) iepg_q_opt="$iepg_q_opt NEWS" ;; 「多」 ) iepg_q_opt="$iepg_q_opt 音声多重" ;; 「新」 ) iepg_q_opt="$iepg_q_opt 新番組" ;; 「天」 ) iepg_q_opt="$iepg_q_opt 天気予報" ;; (終) | 「終」 ) iepg_q_opt="$iepg_q_opt 最終回" ;; * ) ext_str_fin="$ext_str_fin $t2" ;; esac done iepg_ln=${iepg_ln:-80} iepg_q_dd="#$iepg_q_pYmdaHM - $iepg_q_et ${ch}ch #$iepg_q_stn #$iepg_q_ttl" if [ "$iepg_q_sb_ttl" ];then iepg_q_dd="$iepg_q_dd `echo $iepg_q_sb_ttl|nkf -ef$iepg_ln |sed 's/^/#/'`" fi if [ ${iepg_q_ext_v:-0} != 0 ];then iepg_q_dd="$iepg_q_dd #$iepg_q_ext" fi if [ "$iepg_q_dsp" ];then iepg_q_dd="$iepg_q_dd `echo $iepg_q_dsp |nkf -ef$iepg_ln |sed 's/^/#/'`" fi if [ "$iepg_q_pfm" ];then iepg_q_dd="$iepg_q_dd `echo $iepg_q_pfm |nkf -ef$iepg_ln |sed 's/^/#/'`" fi if [ "$iepg_q_opt" ];then iepg_q_dd="$iepg_q_dd #$iepg_q_opt" fi if [ "$iepg_q_tail1" ]&&[ "$ext_str_fin" ];then iepg_q_dd="$iepg_q_dd `echo ${ext_str_fin# } |nkf -ef$iepg_ln |sed 's/^/#/'`" fi else db_echo "$tt is out of iEPG data check." db_echo continue fi fi fi if [ $iepg_vv = 1 ];then title=`echo "$tt_iepg_dd"|grep ^\#program-title:`;title=${title#* } title=`true_title $title` if [ -f $iepg_old ];then title_old="`grep ^program-title: $iepg_old|head -n1`";title_old=${title_old#* } title_old=`true_title $title_old` else title_old=$title fi elif [ "$q_iepg" != 1 ];then title="`grep ^program-title: $iepg_old|head -n1`";title=${title#* } title=`true_title $title` title_old=$title fi title_new="`grep ^program-title: $iepg_new|head -n1`";title_new=${title_new#* } title_new=`true_title $title_new` if [ $iepg_vv = 1 ];then start_time=`grep "^\#$p_iepg_Ymd " $t|grep $p_iepg_HM|head -n1|cut -d' ' -f3` start_time=${start_time#*\(} start_time=${start_time%\)} if [ -f $iepg_old ];then start_time_old="`grep ^start: $iepg_old|head -n1|cut -d' ' -f2`" else start_time_old=$start_time fi elif [ "$q_iepg" != 1 ];then start_time="`grep ^start: $iepg_old|head -n1|cut -d' ' -f2`" start_time_old=$start_time fi start_time_new="`grep ^start: $iepg_new|head -n1|cut -d' ' -f2`" if [ $iepg_vv = 1 ];then end_time=`grep "^\#$p_iepg_Ymd " $t|grep $p_iepg_HM|head -n1|sed 's/ 翌//'|cut -d' ' -f5` end_time=${end_time#*\(} end_time=${end_time%\)} if [ -f $iepg_old ];then end_time_old="`grep ^end: $iepg_old|head -n1|cut -d' ' -f2`" else end_time_old=$end_time fi elif [ "$q_iepg" != 1 ];then end_time="`grep ^end: $iepg_old|head -n1|cut -d' ' -f2`" end_time_old=$end_time fi end_time_new="`grep ^end: $iepg_new|head -n1|cut -d' ' -f2`" if [ $iepg_vv = 1 ];then extend=`echo "$tt_iepg_dd"|grep "^\#Extend:"|cut -d' ' -f2` extend=${extend:-0} if [ -f $iepg_old ];then extend_old=`grep ^Extend: $iepg_old|head -n1|cut -d' ' -f2` extend_old=${extend_old:-0} else extend_old=$extend fi elif [ "$q_iepg" != 1 ];then extend=`grep ^Extend: $iepg_old|head -n1|cut -d' ' -f2` extend=${extend:-0} extend_old=$extend fi extend_new=`grep ^Extend: $iepg_new|head -n1|cut -d' ' -f2` extend_new=${extend_new:-0} if [ "$q_iepg" = 1 ];then true elif [ "$title" != "$title_new" ];then if [ ! "$title_new" ]&&[ ! -f $iepg_new ];then err_mesg="could not get valid iepg file. the program was changed from 「${title}」? the program time may be shifted?" else err_mesg="the title on the program file was changed from「${title}」to「${title_new}」. the program time may be shifted?" fi elif [ "$title_old" != "$title_new" ];then if [ ! "$title_new" ]&&[ ! -f $iepg_new ];then err_mesg="could not get valid iepg file. the program was changed from「${title_old}」? the program time may be shifted?" else err_mesg="the title on iepg file was changed from「${title_old}」to「${title_new}」. the program time may be shifted?" fi iepg_old_xx=1 elif [ "$start_time" != "$start_time_new" ];then err_mesg="start time on the program file was not same on the iEPG file. the program start time may be shifted from $start_time to $start_time_new." elif [ "$start_time_old" != "$start_time_new" ];then err_mesg="start time on the old iEPG file was not same on the new iEPG file. the program start time may be shifted from $start_time_old to $start_time_new." iepg_old_xx=1 elif [ "$end_time" != "$end_time_new" ];then err_mesg="end time on the program file was not same on the iEPG file. the program end time may be shifted from $end_time to $end_time_new." elif [ "$end_time_old" != "$end_time_new" ];then err_mesg="end time on the old iEPG file was not same on the new iEPG file. the program end time may be shifted from $end_time_old to $end_time_new." iepg_old_xx=1 elif [ ${extend:-0} != ${extend_new:-0} ];then if [ "$extend" = 0 ];then err_mesg="end time may be extended for $extend_new." elif [ "$extend_new" = 0 ];then err_mesg="end time extention may be changed from $extend to 0." else err_mesg="end time extention may be changed from $extend to $extend_new." fi elif [ ${extend:-0} != ${extend_old:-0} ];then if [ ${extend_old:-0} = 0 ];then err_mesg="end time may be extended for ${extend:-0}." elif [ "$extend" = 0 ];then err_mesg="end time extention may be changed from ${extend_old:-0} to 0." else err_mesg="end time extention may be changed from ${extend_old:-0} to ${extend:-0}." fi iepg_old_xx=1 else db_echo "$tt; old_ex=$old_ex; iepg_vv=$iepg_vv; wget_err_v=$wget_err_v; iepg_err_v=$iepg_err_v" db_echo "title=$title - title_new=$title_new" db_echo "start_time=$start_time - start_time_new=$start_time_new" db_echo "end_time=$end_time - end_time_new=$end_time_new" db_echo "extend=$extend - extend_new=$extend_new" db_echo "q_iepg=$q_iepg" db_echo OK. db_echo if [ -f $menat_h_t/$e2_iepg_id.e2.iepg ];then rm -f $menat_h_t/$e2_iepg_id.e2.iepg rm -f $menat_h_t/db*prog* fi if [ -f $iepg_new ];then echo "#e2_iepg_id=$e2_iepg_id" >>$iepg_new fi continue fi fi if [ ${debug:-0} -ge 2 ];then read fi if [ ! "$start_t" ];then stn_ma_ex=`grep -n ^\#\!/ $t` stn_n=${stn_ma_ex%%:*} edn_ma_ex=`grep -n ^\$ $t` for n in $edn_ma_ex ;do nn=${n%%:*} if [ $nn -gt ${stn_n:-0} ];then edn_n=$(($nn-1)) break fi done prg_week_v=`$t -c week` prg_auto_exe=`$t -c auto_exe` prg_wkv_str="week=${prg_week_v:-0} ${prg_auto_exe:-0}" prg_iepg_err=`$t -c iepg_err` prg_iepg_err_v="iepg_err=${prg_iepg_err:--1}" cr_version="menat-cr.sh-`$t -c version`" id_dd="#org_id=$prg_org_id:prs_id=$prg_prs_id:sr_id=$prg_sr_id; $prg_wkv_str; $prg_iepg_err_v; $cr_version" prg_menat_user=`$t -c menat_user` prg_menat_host=`$t -c menat_host` prg_exe_hn=`$t -c exe_hn` menat_ui_dd="vs_hn=$vs_hn:user=$prg_menat_user:host=$prg_menat_host:exe_hn=$prg_exe_hn" id_dd="#$menat_ui_dd $id_dd" p_n_YmdaHM=`date '+%Y-%m-%d %a %H:%M'` if [ "$tt_iepg_dd" ]||[ ${out_dd_v:-0} = 1 ];then tt_iepg_dd="checked at $p_n_YmdaHM by $prog_version. $tt_iepg_dd $id_dd " if [ "$q_iepg" = 1 ]&&[ ! "$iepg_re_dd" ];then tt_iepg_dd="$tt_iepg_dd ************** new iEPG data at $p_n_YmdaHM ************** $iepg_q_dd " iepg_e2=3 else if [ -f $iepg_old ]&&[ ${iepg_old_xx:-0} = 1 ];then iepg_xx_f=$iepg_old old_t_YmdHM=`$t -c time_s` old_t_Y=${old_t_YmdHM:0:4} old_t_m=${old_t_YmdHM:4:2} old_t_d=${old_t_YmdHM:6:2} old_t_H=${old_t_YmdHM:8:2} old_t_M=${old_t_YmdHM:10:2} old_p_YmdHM="${old_t_H}:${old_t_M} ${old_t_Y}-${old_t_m}-${old_t_d}" cr_time=`date -d "$old_p_YmdHM" '+%Y-%m-%d %a %H:%M'` tt_mesg="$tt_iepg_dd ************** old iEPG data for $cr_time **************" dd_none=0 elif [ -f $iepg_new ]&&[ ! "$iepg_re_dd" ];then iepg_xx_f=$iepg_new tt_mesg="$tt_iepg_dd ************** new iEPG data at $p_n_YmdaHM **************" iepg_e2=4 dd_none=0 else dd_none=1 fi if [ $dd_none = 0 ];then iepg_q_tail1=`grep -v ': ' $iepg_xx_f|tail -n1` iepg_q_stn=`grep ^station: $iepg_xx_f` iepg_q_ttl=`grep ^program-title: $iepg_xx_f` iepg_q_Y=`grep ^year: $iepg_xx_f|cut -d' ' -f2` iepg_q_m=`grep ^month: $iepg_xx_f|cut -d' ' -f2` iepg_q_d=`grep ^date: $iepg_xx_f|cut -d' ' -f2` iepg_q_st=`grep ^start: $iepg_xx_f|cut -d' ' -f2` q_YmdHM="$iepg_q_st $iepg_q_Y-$iepg_q_m-$iepg_q_d" q_pYmdaHM=`date -d "$q_YmdHM" '+%Y-%m-%d %a %H:%M'` iepg_q_et=`grep ^end: $iepg_xx_f|cut -d' ' -f2` iepg_q_sb_ttl=`grep ^program-subtitle: $iepg_xx_f` iepg_q_ext=`grep ^Extend: $iepg_xx_f` iepg_q_ext_v=`grep ^Extend: $iepg_xx_f|cut -d' ' -f2` iepg_opt_str=`echo $iepg_q_tail1|sed 's/」/」 /g;s/「/ 「/g;s/(終)/ (終) /g'` iepg_q_dsp=`grep ^description: $iepg_xx_f` iepg_q_pfm=`grep ^performer: $iepg_xx_f` iepg_q_opt="" ext_str_fin="" for t2 in $iepg_opt_str ;do case $t2 in 「S」 ) iepg_q_opt="$iepg_q_opt STEREO" ;; 「字」 ) iepg_q_opt="$iepg_q_opt 文字多重" ;; 「E」 ) iepg_q_opt="$iepg_q_opt 二ヵ国語" ;; 「再」 ) iepg_q_opt="$iepg_q_opt 再放送" ;; 「N」 ) iepg_q_opt="$iepg_q_opt NEWS" ;; 「多」 ) iepg_q_opt="$iepg_q_opt 音声多重" ;; 「新」 ) iepg_q_opt="$iepg_q_opt 新番組" ;; 「天」 ) iepg_q_opt="$iepg_q_opt 天気予報" ;; (終) | 「終」 ) iepg_q_opt="$iepg_q_opt 最終回" ;; * ) ext_str_fin="$ext_str_fin $t2" ;; esac done iepg_ln=${iepg_ln:-80} iepg_q_dd="#$q_pYmdaHM - $iepg_q_et ${ch}ch #$iepg_q_stn #$iepg_q_ttl" if [ "$iepg_q_sb_ttl" ];then iepg_q_dd="$iepg_q_dd `echo $iepg_q_sb_ttl|nkf -ef$iepg_ln |sed 's/^/#/'`" fi if [ ${iepg_q_ext_v:-0} != 0 ];then iepg_q_dd="$iepg_q_dd #$iepg_q_ext" fi if [ "$iepg_q_dsp" ];then iepg_q_dd="$iepg_q_dd `echo $iepg_q_dsp |nkf -ef$iepg_ln |sed 's/^/#/'`" fi if [ "$iepg_q_pfm" ];then iepg_q_dd="$iepg_q_dd `echo $iepg_q_pfm |nkf -ef$iepg_ln |sed 's/^/#/'`" fi if [ "$iepg_q_opt" ];then iepg_q_dd="$iepg_q_dd #$iepg_q_opt" fi if [ "$iepg_q_tail1" ]&&[ "$ext_str_fin" ];then iepg_q_dd="$iepg_q_dd `echo ${ext_str_fin# } |nkf -ef$iepg_ln |sed 's/^/#/'`" fi tt_iepg_dd="$iepg_dd $tt_mesg $iepg_q_dd " fi fi else iepg_dd=`sed -n "${edn_n}p" $t` tt_iepg_dd="checked at $p_n_YmdaHM by $prog_version. $iepg_dd $id_dd " fi fi if [ "$iepg_re_dd" ];then tt_iepg_dd="$tt_iepg_dd ************** new iEPG data at $p_n_YmdaHM ************** $iepg_re_dd " iepg_e2=5 fi db_echo "$tt; old_ex=$old_ex; iepg_vv=$iepg_vv; wget_err_v=$wget_err_v; iepg_err_v=$iepg_err_v" db_echo "title=${title:-null} - title_old=${title_old:-null} - title_new=${title_new:-null}" db_echo "start_time=${start_time:-null} - start_time_old=${start_time_old:-null} - start_time_new=${start_time_new:-null}" db_echo "end_time=${end_time:-null} - end_time_old=${end_time_old:-null} - end_time_new=${end_time_new:-null}" db_echo "extend=$extend - extend_old=$extend_old - extend_new=$extend_new" db_echo "q_iepg=$q_iepg" db_echo db_echo "error occured: $err_mesg" db_echo "$tt_iepg_dd" echo "$err_mesg $tt_iepg_dd" >$iepg_mesg chmod -f 664 $iepg_mesg db_echo echo >>$menat_log echo "$tt: $err_mesg" >>$menat_log to_addr=`$t -c menat_user` if [ "$debug" ];then db_echo "$menat_mail -a ${to_addr:-menat} -p 3 -vs $vs_hn -i $tt -n $iepg_mesg" db_echo else if [ ${iepg_e2:-0} != 0 ];then if [ $old_ex = 1 ];then e2_iepg_id_old=`grep e2_iepg_id= $iepg_old` e2_iepg_id_old=${e2_iepg_id_old#*=} if [ $e2_iepg_id = ${e2_iepg_id_old:-$e2_iepg_id} ];then e2_iepg_wrn=1 else e2_iepg_wrn=0 fi else e2_iepg_wrn=1 fi if [ $e2_iepg_wrn = 1 ];then cat $iepg_mesg >$menat_h_t/$e2_iepg_id.e2.iepg chmod -f 777 $menat_h_t/$e2_iepg_id.e2.iepg rm -f $menat_h_t/db*prog* fi fi $menat_mail -a ${to_addr:-menat} -p 3 -vs $vs_hn -i $tt -n $iepg_mesg echo "$prog_version: $menat_mail -a ${to_addr:-menat} -p 3 -vs $vs_hn -i $tt -n $iepg_mesg" >>$menat_log if [ "$prog_reget_ok" = 1 ];then lang_t=$LANG;LANG=C LANG=$lang_t rn=1 rm_cap_dev=${tt:14:1} case $rm_cap_dev in '.' ) rm_2p="" ;rm_cap_dev=0;; * ) rm_2p=$rm_cap_dev ;; esac rm_exe_v=`$t -c exe_v` rm_exe_nv=$((${rm_exe_v:-0}-4)) tt_12=${tt:0:12} tt_epm=`$t -c time_epm` tt_ch=`$t -c ch` tt_bfn=`$t -c bfn` tt_opt1=`$t -c opt1` if [ "$tt_opt1" ];then tt_opt1=":$tt_opt1" else tt_opt1="" fi tt_week=`$t -c week`;tt_week=${tt_week:-0} tt_user=`$t -c menat_user` tt_host=$exe_hn tt_input=`$t -c input_v` rm_to_f=$menat_h_t/$tt_12.$rm_cap_dev$rn.mtq while [ -f $rm_to_f ];do if [ $rn -ge 255 ];then while [ $rn != 0 ];do mv -f $rm_to_f $menat_h_t/$tt_12.$rm_cap_dev$(($rn-1)).mtq rn=$(($rn-1)) done rn=255 break fi rn=$(($rn+1)) rm_to_f=$menat_h_t/$tt_12.$rm_cap_dev$rn.mtq done cp -f $menat_h/$tt $rm_to_f;cp_v=$? cp -f $menat_h/$tt $rm_to_f.back;cp_v=$? #echo "cp -f $menat_h/$tt $rm_to_f;cp_v=$cp_v" rm_err_0="mv -f $menat_h/$tt $rm_to_f;mv_v=$cp_v" if [ -f $rm_to_f ];then ed -s $rm_to_f >/dev/null 2>&1 <$iepg_mesg else reg_p=5 echo "ERROR OCCURED! $tt reget failed by $reget_err!" >$iepg_mesg fi $menat_mail -a ${tt_user} -p $reg_p -vs $vs_hn -i $tt -n $iepg_mesg echo "$prog_version: $menat_mail -a ${tt_user} -p $reg_p -vs $vs_hn -i $tt -n $iepg_mesg" >>$menat_log else tmp_YmdaHM=`date '+%Y-%m-%d %a %H:%M'` echo "#${tmp_YmdaHM}, this program was removed by ${prog_version}." >>$rm_to_f reget_done=1 rm -f $rm_to_f.back rm -f $menat_h_t/db*prog* fi fi if [ -f $iepg_new ]&&[ "$reget_done" != 1 ];then echo "#e2_iepg_id=$e2_iepg_id" >>$iepg_new fi fi err_ls="$err_ls $tt" done err_ls=${err_ls# } err_ls=${err_ls:-none} prg_err_ls="${err_ls}" echo >>$menat_log echo "menat-progchk-$version: checked at `date '+%Y-%m-%d %a %H:%M'`." >>$menat_log echo "error_list: $err_ls." >>$menat_log i=1 for t in `ls -r $menat_iepg/*.progchk 2>/dev/null` ;do if [ $i -gt 2 ];then rm -f $t fi i=$(($i+1)) done pn_time=`date '+%Y-%m-%d %a %H:%M'` iepg_log=$menat_iepg/$n_YmdHM.progchk db_echo "menat-progchk-$version: checked at $pn_time." if [ ${prg_verbose:-0} = 1 ];then echo $prg_err_ls else db_echo "error_list: $err_ls." fi echo "menat-progchk-$version: checked at $pn_time." >$iepg_log echo "error_list: $err_ls." >>$iepg_log rm -f $menat_iepg/[12345678]_[01234][0-9].html rm -f $menat_iepg/prog_tt* exit 0 #2005-05-23 Mon 17:08 tail bug was fixed at 0.7.2. #2005-05-21 Sat 20:22 end_time bug was fixed, and 0.7.x series started. #2005-05-18 Thu 00:39 new ls compatibility at 0.6.14. #2005-04-08 Fri 04:48 debug process usability was revised at 0.6.12. #2005-04-02 Sat 19:00 7002 db bug was fixed at 0.6.10. #2005-03-31 Thu 02:41 many bugs were fixed at 0.6.8. #2005-03-29 Tue 00:54 -d option was implemented at 0.6.0. #2005-03-27 Sun 17:45 TVガイド対応 at 0.5.1. #2005-03-27 Sun 03:45 -V -S -r option was implemented at 0.5.0. #2005-03-26 Sat 10:58 p option bug was fixed at 0.4.6. #2005-03-25 Fri 18:00 iepg_Ymd bug was fixed at 0.4.4. #2005-03-21 Mon 20:50 st_id.db was updated and many bugs were fixed at 0.4.2. #2005-03-20 Sun 09:50 err_mesg format was revised for iepg data at 0.4.0 #2005-03-04 Fri 04:00 first official release at 0.3.0. #2005-03-02 Wed 09:11 process to remove file time expire was implemented at 0.2.6. #2005-03-01 Tue 10:00 interactive option -i was implemented at 0.1.7. #2005-02-28 Mon 12:50 first release 0.1.0.