#!/bin/sh #Execute for menat. # version=1.2.2-pre2 sad_version=menat-sad.sh-$version LANG=C exe_user=`id -un` 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} fi return $dvn_v } p_date() { d12_Y=${1:0:4} d12_m=${1:4:2} d12_d=${1:6:2} d12_H=${1:8:2} d12_M=${1:10:2} date -d "$d12_Y-$d12_m-$d12_d $d12_H:$d12_M" '+%Y-%m-%d %a %H:%M' } 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 } user_h=/var/menat menat_sys_d=/etc/menat org_log=$user_h/localhost/menat/tmp/menat.log if [ ! -w $org_log ];then t=0 while [ -f /tmp/menat.log$tt ]&&[ ! -w /tmp/menat.log$tt ];do t=$(($t+1)) tt=.$t done fi vs_ls=`cat $menat_sys_d/vs.list` while [ "$1" ];do case $1 in -vs ) shift vs_name=$1 ma_host=`host $vs_name` ma_host=${ma_host##* } shift ;; -l ) shift lock_off=1 lock_off2=1 lock_off_f=$1 shift ;; -D ) shift debug=$1 shift ;; * ) if [ ! "$pp_d" ];then pp_d=$1 elif [ ! "$shutdown_no" ];then shutdown_no=$1 else pp_d2=$1 fi shift ;; esac done vs_name=${vs_name:-`hostname`} for t in $vs_ls ;do if [ $t = $vs_name ];then vs_name=$t break else vs_name=localhost fi done ma_host=${ma_host:-`hostname -i`} ma_user=menat pp_d=${pp_d:-unknown} vs_h=$user_h/$vs_name vs_hn=${vs_name%%.*} menat_h=$vs_h/menat menat_h_t=$menat_h/tmp ma_h=$vs_h/vfiles ma_h_t=$ma_h/tmp menat_bin=$user_h/bin menat_sad=$menat_bin/menat-sad.sh menat_mail=$menat_bin/menat-mail.sh menat_iepg=$vs_h/iepg menat_progchk=$menat_bin/menat-progchk.sh menat_html=/var/menat/public_html menat_lock=$menat_h_t/lock.menat sad_lock=$menat_h_t/sad.lock menat_log=$menat_h_t/menat.log vs_lock_2=$menat_html/.ttf_err wget_pass="" cgi_pass="" if [ -f $menat_sys_d/menat.conf ];then shutdown_ok=`. $menat_sys_d/menat.conf;echo $shutdown_ok` shtd_span=`. $menat_sys_d/menat.conf;echo $shtd_span` ht_ex_time=`. $menat_sys_d/menat.conf;echo $ht_ex_time` sleep_m=`. $menat_sys_d/menat.conf;echo $sleep_m` httpd_log=`. $menat_sys_d/menat.conf;echo $httpd_log` log_chk=`. $menat_sys_d/menat.conf;echo $log_chk` prog_chk=`. $menat_sys_d/menat.conf;echo $prog_chk` menat_sd_exe=`. $menat_sys_d/menat.conf;echo $menat_sd_exe` tcp_lock=`. $menat_sys_d/menat.conf;echo $tcp_lock` sad_dl_rist=`. $menat_sys_d/menat.conf;echo $sad_dl_rist` t_mtq_mx=`. $menat_sys_d/menat.conf;echo $t_mtq_mx` ma_bp=`. $menat_sys_d/menat.conf;echo $ma_bp` cgi_passwd=`. $menat_sys_d/menat.conf;echo $cgi_passwd` if [ -f "$cgi_passwd" ];then vs_auth=`grep $vs_name $cgi_passwd|head -n 1` if [ "$vs_auth" ];then cgi_pass=${vs_auth#*:}@ else cgi_pass="" fi fi fi if [ -f $menat_sys_d/menat-sad.conf ];then shutdown_ok=`. $menat_sys_d/menat-sad.conf;echo $shutdown_ok` shtd_span=`. $menat_sys_d/menat-sad.conf;echo $shtd_span` ht_ex_time=`. $menat_sys_d/menat-sad.conf;echo $ht_ex_time` sleep_m=`. $menat_sys_d/menat-sad.conf;echo $sleep_m` httpd_log=`. $menat_sys_d/menat-sad.conf;echo $httpd_log` log_chk=`. $menat_sys_d/menat-sad.conf;echo $log_chk` prog_chk=`. $menat_sys_d/menat-sad.conf;echo $prog_chk` menat_sd_exe=`. $menat_sys_d/menat-sad.conf;echo $menat_sd_exe` tcp_lock=`. $menat_sys_d/menat-sad.conf;echo $tcp_lock` sad_dl_rist=`. $menat_sys_d/menat.conf;echo $sad_dl_rist` ma_dl_ristriction=`. $menat_sys_d/menat.conf;echo $ma_dl_ristriction` fi vs_uri="http://$cgi_pass$vs_name/~menat" if [ -f $menat_sys_d/backup.conf ];then ma_bc_bp=`. $menat_sys_d/backup.conf;echo $ma_bp` ma_bp=${ma_bc_bp:-$ma_bp} fi shutdown_ok=`n_ident ${shutdown_ok:-0}` shtd_span=`n_ident ${shtd_span:-70} 70` ht_ex_time=`n_ident ${ht_ex_time:-30} 30` t_mtq_mx=`n_ident ${t_mtq_mx:-256} 256` sleep_m=`n_ident ${sleep_m:-10} 10` httpd_log=${httpd_log:-/var/log/httpd/access_log} sad_htaccess=${sad_htaccess:-$menat_bin/menat_htaccess} if [ -d "$ma_bp" ];then http_bp=`. $menat_sys_d/menat.conf;echo $http_bp` http_bp=${http_bp:-/var/menat/public_html/bp} if [ -e $http_bp ];then http_bp_ok=1 else http_bp_ok=0 fi else http_bp_ok=0 fi log_chk=${log_chk:-0} prog_chk=${prog_chk:-$vs_hn} if [ "$shutdown_no" ];then shutdown_ok=0 shtd_v1=${pp_d##*menat-cr.sh*} shtd_v2=${shutdown_no##*menat-cr.sh*} if [ "$pp_d" ]&&[ ! "$shtd_v1" ];then lock_off=1 elif [ ! "$shtd_v2" ];then lock_off=1 fi elif [ $pp_d = start ];then shutdown_ok=0 fi if [ -f $menat_sys_d/capture.conf ];then ma_ext=`. $menat_sys_d/capture.conf;echo $ma_ext` fi ma_ext=${ma_ext:-mjp} ms_time=`date '+%Y-%m-%d %a %H:%M'` if [ "$pp_d" = s ];then echo >>$menat_log echo '*******************************************************' >>$menat_log echo "menatd: `rpm -q menat`" >>$menat_log echo "menatd: $sad_version start from s." >>$menat_log rm -rf $menat_html/.htrm* fi if [ $exe_user = root ];then ma_atq="sudo /bin/su - menat -c atq" ma_at="sudo /bin/su - menat -c at" if [ ! -f $menat_log ];then echo "$sad_version: menat.log was created at $ms_time by root in $pp_d." >>$menat_log fi dvn=`chown -f menat.menat $menat_log $menat_log >/dev/null 2>&1` dvn=`chmod -f 664 $menat_log $menat_log >/dev/null 2>&1` elif [ $exe_user = menat ];then ma_atq=atq ma_at=at if [ -f $menat_log ];then if [ ! -w $menat_log ];then menat_log=${menat_log}.save echo "$sad_version: for permission error at $ms_time by menat in $pp_d." >>$menat_log fi else echo "$sad_version: menat.log was created at $ms_time by menat in $pp_d." >>$menat_log fi else logger -p local7.notice "menatd: not authoraized user $exe_user executed $sad_version in ${pp_d}." exit 1 fi ################################################################################################# ################################################################################################# ################################################################################################# menat_sd() { exe_shtd_ok=0 menat_exe_lock=0 ### tcp_lock=1 http_lock=2 nxt_job_lock=4 login_lock=8 ### cap_exe_lock=1 com_exe_lock=2 if [ -d $menat_lock ];then for t in $menat_lock/* ;do if [ -f $t ];then if [ "$cap_run_ls" ];then cap_run_ls="$cap_run_ls,${t##*/}" else cap_run_ls="${t##*/}" fi fi done if [ "$cap_run_ls" ];then echo "capturing $cap_run_ls now. does not shutdown." >>$menat_log else echo "none running cap_lock, but lock.menat exists. Why?" >>$menat_log fi return 0 else menat_exe_lock=1 fi if [ -f $menat_h_t/shut_al ];then echo "now in shutdown process." >>$menat_log echo >>$menat_log echo in_shutdown return 0 fi if [ "$tcp_lock" != 0 ];then tcp_est_ls=`netstat -t |grep 'tcp.*ESTABLISHED'|tr -s ' ' ' '|cut -d' ' -f4` if [ "$tcp_est_ls" ];then for t in $tcp_est_ls ;do t_service=${t##*:} dvn=`n_ident $t_service`;dvn_v=$? if [ $dvn_v = 0 ];then continue else est_ls_str=`expand /etc/services|grep "^$t .*/tcp"|tr -s ' ' ' '|cut -d' ' -f2` pri_port_ok=1 for t1 in $est_ls_str ;do est_port=${t1%/tcp} if [ $est_port -gt 1023 ];then pri_port_ok=0 else pri_port_ok=1 break fi done if [ $pri_port_ok = 0 ];then continue fi fi if [ "$tcp_est" ];then tcp_est="$tcp_est,$t" tcp_a=are else tcp_est=$t tcp_a=is fi done if [ "$tcp_est" ];then p_tcp_lt="$tcp_est $tcp_a running." else exe_shtd_ok=$(($exe_shtd_ok+1)) fi else exe_shtd_ok=$(($exe_shtd_ok+1)) fi else exe_shtd_ok=$(($exe_shtd_ok+1)) fi if [ $ht_ex_time != 0 ];then if [ `netstat -t|grep -c 'http *ESTABLISHED'` = 0 ];then dvn=`n_ident $ht_ex_time`;dvn_v=$? if [ $dvn_v != 0 ];then ht_ex_time=30 fi if [ -r $httpd_log ];then http_t1=`ft_date $httpd_log` else http_t1="" for t in /var/menat/public_html/*.cgi ;do fa_YmdHM=`find $t -maxdepth 0 -follow -printf '%AY%Am%Ad%AH%AM'` if [ ! "$http_t1" ];then http_t1=$fa_YmdHM else if [ "$fa_YmdHM" '>' "$http_t1" ];then http_t1=$fa_YmdHM fi fi done fi ht_Y=${http_t1:0:4} ht_m=${http_t1:4:2} ht_d=${http_t1:6:2} ht_H=${http_t1:8:2} ht_M=${http_t1:10:2} ht_pHM="$ht_H:$ht_M" hta_lt=`date -d "$ht_Y-$ht_m-$ht_d $ht_pHM" '+%s'` p_hta_lt=`date -d "$ht_Y-$ht_m-$ht_d $ht_pHM" '+%Y-%m-%d %a %H:%M'` ex_t=`date -d "-${ht_ex_time}minute" '+%s'` else hta_lt=1 p_hta_lt="running" ex_t=0 fi if [ ${ex_t:-1} -ge ${hta_lt:-0} ];then exe_shtd_ok=$(($exe_shtd_ok+2)) http_exp=1 else http_exp=0 fi else http_exp=1 hta_lt=0 p_hta_lt="disable" ex_t=1 exe_shtd_ok=$(($exe_shtd_ok+2)) fi ex_ft=`date -d "${shtd_span}minute" '+%Y%m%d%H%M'` nxt_jb_org=`$ma_atq|sort -k2|grep -v '='|head -n 1|cut -f2|cut -d" " -f1-2` nxt_jb=`echo $nxt_jb_org|sed 's/://g;s/ //g;s/-//g'` if [ ! "$nxt_jb" ];then exe_shtd_ok=$(($exe_shtd_ok+4)) nxt_job_msg="next job is none." elif [ "`ls $menat_h/$nxt_jb.w*`" ];then r=`ls $menat_h/$nxt_jb.w*|head -n1` r_b=${r##*/} nx_jb_st=`$r -c time_s` nxj_Ymd=${nx_jb_st:0:8} nxj_H=${nx_jb_st:8:2} nxj_M=${nx_jb_st:10:2} nxj_st=`date -d "$nxj_Ymd $nxj_H:$nxj_M" '+%Y-%m-%d %a %H:%M'` nx_jb_epm=`$r -c time_epm` nx_jb_pch=`$r -c pch` nx_jb_nf=`$r -c bfn` nxj_ed_p_HM=`date -d "$nxj_Ymd $nxj_H:$nxj_M ${nx_jb_epm}minute" '+%H:%M'` nxt_jb_p="$nxj_st - $nxj_ed_p_HM ${nx_jb_pch:-unknown} $nx_jb_nf" if [ "$ex_ft" '>' "$nxt_jb" ];then nxt_job_msg="next job is $r_b. $nxt_jb_p the next job must be executed soon." else exe_shtd_ok=$(($exe_shtd_ok+4)) nxt_job_msg="next job $r_b is not scheduled soon. $nxt_jb_p" fi else nxt_jb_p="unknown error occured." exe_shtd_ok=$(($exe_shtd_ok+4)) fi login_u=`w -h|cut -d' ' -f1` if [ ! "$login_u" ];then exe_shtd_ok=$(($exe_shtd_ok+8)) login_u_ls=none login_u_n=0 else for t in $login_u ;do if [ "$login_u_ls" ];then lu_d=0 for t1 in $login_u_ls2 ;do if [ $t = $t1 ];then lu_d=1 break fi done if [ $lu_d = 1 ];then continue fi login_u_n=$(($login_u_n+1)) login_u_ls="$login_u_ls,$t" login_u_ls2="$login_u_ls2 $t" else login_u_ls="$t" login_u_ls2="$t" login_u_n=1 fi done fi ln_v=`ls -1d $menat_h_t/lock.* 2>/dev/null`;lv=$? cmp_ls_n=0 cmp_w_n=0 cmp_r_n=0 if [ "$ln_v" ];then for t in $ln_v ;do if [ $t = $menat_h_t/lock.menat ];then continue else cmp_ls_n=$(($cmp_ls_n+1)) if [ `grep -c ^menat_cmp_id $t` = 0 ];then if [ "$cmp_w_ls" ];then cmp_w_ls="$cmp_w_ls,${t#$menat_h_t/lock.}" cmp_w_n=$(($cmp_w_n+1)) else cmp_w_ls=${t#$menat_h_t/lock.} cmp_w_n=1 fi else if [ "$cmp_r_ls" ];then cmp_r_ls="$cmp_r_ls,${t#$menat_h_t/lock.}" cmp_r_n=$(($cmp_r_n+1)) else cmp_r_ls=${t#$menat_h_t/lock.} cmp_r_n=1 fi fi fi done if [ $cmp_ls_n != 0 ];then if [ "$cmp_r_ls" ]||[ "$cmp_w_ls" ];then if [ "$cmp_w_ls" ];then cmp_msg="wait to compress $cmp_w_ls." fi if [ "$cmp_r_ls" ];then if [ "$cmp_msg" ];then cmp_msg="$cmp_msg now compressing $cmp_r_ls." else cmp_msg="now compressing $cmp_r_ls." fi fi else menat_exe_lock=$(($menat_exe_lock+2)) cmp_msg="any compress jobs are not in que." fi else menat_exe_lock=$(($menat_exe_lock+2)) cmp_msg="any compress jobs are not in que." fi else menat_exe_lock=$(($menat_exe_lock+2)) cmp_msg="any compress jobs are not in que." if [ $men_ex_n != 0 ];then cmp_msg="unknown mencoder process is running." fi fi echo login user: $login_u_ls >>$menat_log nn_Ymd=`date '+%Y-%m-%d'` t1_v2=`$ma_atq|grep -c "$nn_Ymd"` if [ "$t1_v2" = 0 ];then echo "all today's job has been executed already." >>$menat_log job=job;is=is else echo "today's jobs." >>$menat_log $ma_atq|grep "$nn_Ymd" |sort -k3 >>$menat_log if [ "$t1_v2" -gt 1 ];then job=jobs;is=are else job=job;is=is fi fi echo "$nxt_job_msg" >>$menat_log echo "$cmp_msg" >>$menat_log if [ "$p_hta_lt" ]&&[ $ht_ex_time != 0 ];then if [ "$p_hta_lt" != running ];then echo "httpd last access time is $p_hta_lt." >>$menat_log else echo "httpd is $p_hta_lt, now." >>$menat_log fi else if [ $ht_ex_time != 0 ];then echo "ERROR: p_hta_lt=$p_hta_lt, ht_ex_time=$ht_ex_time" >>$menat_log fi fi if [ "$p_hta_lt" = disable ];then echo "httpd lock disabled." >>$menat_log elif [ "$p_hta_lt" ];then if [ $http_exp = 1 ];then echo "httpd lock expired, ht_ex_time=$ht_ex_time." >>$menat_log elif [ "$p_hta_lt" != running ];then lt_S=$(($hta_lt-$ex_t)) lt_M=$(($lt_S/60));lt_M_r=$(($lt_S%60)) if [ $lt_M_r -ge 30 ];then lt_M=$(($lt_M+1)) fi if [ $lt_M = 1 ]||[ $lt_M = 0 ];then minute=minute else minute=minutes fi echo "httpd lock active, ht_ex_time=$ht_ex_time. left $lt_M$minute." >>$menat_log else echo "httpd lock active, ht_ex_time=$ht_ex_time." >>$menat_log fi else echo "httpd lock none." >>$menat_log fi if [ "$p_tcp_lt" ];then echo "$p_tcp_lt" >>$menat_log fi mnn=`ps axcu|grep -c "^menat.*mencoder"` if [ $(($mnn-$cmp_r_n)) = 0 ];then menat_exe_lock=$(($menat_exe_lock+4)) fi echo "user login $login_u_n, today's $job $is $t1_v2." >>$menat_log echo "compress job $cmp_ls_n in que, running mencoder $mnn." >>$menat_log echo "exe_shtd_ok=$exe_shtd_ok, menat_exe_lock=$menat_exe_lock" >>$menat_log if [ $exe_shtd_ok != 15 ]||[ $menat_exe_lock != 7 ];then echo "the shutdown conditions are not cleared." >>$menat_log echo "does not shutdown." >>$menat_log if [ -f $menat_h_t/shut_al ];then rm -f $menat_h_t/shut_al fi else if [ ! -f $menat_h_t/shut_al ];then touch $menat_h_t/shut_al;sal_v=$? if [ $sal_v = 0 ];then echo "clear all shutdown condition." >>$menat_log else echo -n "clear all shutdown codition, but failed to create shut_al." >>$menat_log fi else echo "now in shutdown process." >>$menat_log echo >>$menat_log echo in_shutdown return 0 fi if [ -x "$menat_sd_exe" ];then echo "execute ${menat_sd_exe##*/} in shutdown process." >>$menat_log sd_ex_rv=`$menat_sd_exe` fi if [ ! -f $menat_h_t/shut_al ];then echo "unexpected error occured in shutdown process, shut_al is none." >>$menat_log return 1 elif [ -d $menat_lock ];then echo "unexpected error occured in shutdown process, menat_lock exists." >>$menat_log rm -f $menat_h_t/shut_al return 1 else for t in $menat_h_t/lock.* ;do if [ -f $t ];then shut_cmp_ls="$shut_cmp_ls $t" fi done if [ "$shut_cmp_ls" ];then echo "unexpected error occured in shutdown process, cmp_ls exists." >>$menat_log echo "${shut_cmp_ls}." >>$menat_log return 1 fi fi ma_id_ln=$((`wc -l <$menat_h_t/ma_id.db`)) ma_h_fn=$((`ls -l $ma_h/|grep -c ^-`)) if [ ${shtd_re_db:-0} = 1 ]||[ $ma_id_ln != $ma_h_fn ]||[ -f $vs_lock_2 ];then echo "ma_id_ln=$ma_id_ln, ma_h_fn=$ma_h_fn, re_db was executrd." >>$menat_log wget -O /dev/null $vs_uri/menat-vs.cgi?re_db=1\&vs_hn=$vs_hn if [ -f $vs_lock_2 ];then rm -f $vs_lock_2 >/dev/null fi fi wget -O /dev/null $vs_uri/menat-vs.cgi?mdss=1\&vs_hn=$vs_hn wget -O $menat_h_t/vs.html $vs_uri/menat-vs.cgi?shtd=1\&vs_hn=$vs_hn shtd_YmdaHM=`date '+%Y-%m-%d %a %H:%M'` echo "$shtd_YmdaHM, shutdown was executed by $exe_user." >>$menat_log if [ ${pp_d:0:4} != LOOP ];then echo "$sad_version from $pp_d end." >>$menat_log echo '*******************************************************' >>$menat_log fi rm -f $menat_h_t/*.tmp rm -f $menat_h_t/sad.loop echo "$sad_version at $shtd_YmdaHM" >$menat_h_t/shut_al mv -f $menat_h_t/shut_al $menat_h_t/shut_al.end sudo /sbin/shutdown -h now echo shutdown return 0 fi return 0 } at_add_ps() { mn_time=`date '+%Y-%m-%d %a %H:%M'` time_at="$1" at_add_f=$2 aa_fn=${at_add_f##*/} aa_fn_12=${aa_fn%%.*} re_ad_v=$3 cap_dev_t=`$at_add_f -c cap_dev` case ${cap_dev_t#/dev/video} in 0 ) cap_dev_n="" ;; * ) cap_dev_n=${cap_dev_t#/dev/video} ;; esac nme_s=`grep -c '^#external_exe_start' $at_add_f` nme_e=`grep -c '^#external_exe_end' $at_add_f` if [ ${nme_s:-0} = 1 ]&&[ ${nme_e:-0} = 1 ];then at_ma_ex=$menat_h_t/nw_ma_ex sed -n '1,/external_exe_start/p;/external_exe_end/,/maexe_file_end/p' $at_add_f >$at_ma_ex else at_ma_ex=$at_add_f fi atq_rv=`$ma_at -f $at_ma_ex $1 2>&1`;at_v=$? if [ $at_v = 0 ];then rv_HM=${1:0:5} rv_Ymd=${1:6} nw_prs_id=`echo "$atq_rv"|grep "$rv_Ymd $rv_HM"|head -n1|cut -d' ' -f2` nw_ma_ex=$menat_h/$aa_fn_12.w$cap_dev_n.mtq if [ $at_add_f != $nw_ma_ex ];then cp -f $at_add_f $nw_ma_ex rm -f $at_add_f fi chmod -f 775 $nw_ma_ex if [ "$re_ad_v" = 1 ];then p_re_added="re-added" else p_re_added="added" fi echo -n '#'`$ma_atq|grep "^$nw_prs_id\>"` >>$nw_ma_ex echo " menat_que_record" >>$nw_ma_ex echo "#$mn_time $ma_fn was $p_re_added in que." >>$nw_ma_ex echo "${ma_fn}:${nw_prs_id} was $p_re_added in que at ${mn_time}." >>$menat_log else echo "at faild for ${aa_fn} at ${mn_time}." >>$menat_log return $at_v fi end_ln=`grep -nv '^#' $nw_ma_ex|head -n1` iepg_dd=`sed -n "4,$((${end_ln%%:*}-1))p" $nw_ma_ex` echo "$iepg_dd" >>$nw_ma_ex nw_vs_hn=`$nw_ma_ex -c vs_hn` nw_user=`$nw_ma_ex -c menat_user` nw_host=`$nw_ma_ex -c menat_host` nw_exe_hn=`$nw_ma_ex -c exe_hn` nw_week=`$nw_ma_ex -c week` if [ ! "$nw_week" ];then nw_week=0 fi nw_cr_version="menat-cr.sh-`$nw_ma_ex -c version`" nw_auto_exe=`$nw_ma_ex -c auto_exe` nw_auto_exe=${auto_exe:-0} nw_week_v="week=$nw_week $nw_auto_exe" nw_iepg_err=`$nw_ma_ex -c iepg_err` nw_iepg_err_v="iepg_err=${nw_iepg_err:--1}" nw_org_id=`$nw_ma_ex -c org_id` nw_sr_id=`$nw_ma_ex -c sr_id` if [ ! "$nw_org_id" ];then nw_org_id=$nw_prs_id nw_sr_id=0 fi if [ ! "$nw_sr_id" ];then nw_sr_id=0 fi add_str1="#vs_hn=$nw_vs_hn:user=$nw_user:host=$nw_host:exe_hn=$nw_exe_hn" add_id_str="org_id=$nw_org_id;prs_id=$nw_prs_id;sr_id=$nw_sr_id" ed -s $nw_ma_ex >/dev/null 2>&1 <>$nw_ma_ex echo $add_str2 >>$nw_ma_ex rm -f $menat_h_t/*.t.db* rm -f $menat_h_t/db*prog* return 0 } cap_end_ps() { mn_time=`date '+%Y-%m-%d %a %H:%M'` cap_end_f=$1 ce_fn=${cap_end_f##*/} cap_dev_t=`$cap_end_f -c cap_dev` case ${cap_dev_t#/dev/video} in 0 ) cap_dev_n="" ;; * ) cap_dev_n=${cap_dev_t#/dev/video} ;; esac if [ -f $menat_lock/${pp_d%%:*} ];then cap_vv=`grep 'cap_v=.*:end$' $menat_lock/${pp_d%%:*}|tail -n1|cut -d':' -f6|cut -d'=' -f2` fi ce_fn_12=${ce_fn%%.*} ce_exe_v=`$cap_end_f -c exe_v` dvn=`n_ident $ce_exe_v`;n_v=$? if [ $n_v != 0 ];then ce_exe_v=-127 fi if [ $ce_exe_v -ge 0 ];then if [ $ce_exe_v = 0 ];then exe_v_st="exe_v=0" echo "capture was done." >>$menat_log ma_ex_exp=$menat_h_t/$ce_fn_12.s$cap_dev_n.mtq elif [ $ce_exe_v = 125 ];then exe_v_st="exe_v=125" echo "capture was time out." >>$menat_log ma_ex_exp=$menat_h_t/$ce_fn_12.t$cap_dev_n.mtq else exe_v_st="exe_v=${ce_exe_v}" echo "capture was done, but failed." >>$menat_log ma_ex_exp=$menat_h_t/$ce_fn_12.f$cap_dev_n.mtq fi else cap_v=`grep -c ' menat_ends$' $cap_end_f` cap_v2=`grep -c ' capture_failed menat_ends$' $cap_end_f` cap_v3=`grep -c ' capture_time_out menat_ends$' $cap_end_f` if [ $cap_v2 != 0 ];then exe_v_st="exe_v=${cap_vv:-15}" echo "capture was done, but failed." >>$menat_log ma_ex_exp=$menat_h_t/$ce_fn_12.f$cap_dev_n.mtq elif [ $cap_v3 != 0 ];then exe_v_st="exe_v=125" echo "capture was time out." >>$menat_log ma_ex_exp=$menat_h_t/$ce_fn_12.t$cap_dev_n.mtq elif [ $cap_v != 0 ];then exe_v_st="exe_v=0" echo "capture was done." >>$menat_log ma_ex_exp=$menat_h_t/$ce_fn_12.s$cap_dev_n.mtq else exe_v_st="exe_v=${cap_vv:-16}" if [ `grep -c '^#force_exe' $cap_end_f` = 0 ];then echo "capture was not executed, force to execute $ce_fn." >>$menat_log echo "#force_exe $ce_fn at $mn_time by $sad_version from $pp_d." >>$cap_end_f cp -af $cap_end_f $menat_h_t/ce_exe.$$ force_v=`$menat_h_t/ce_exe.$$` echo "force_v: $force_v" >>$menat_log mv -f $menat_h_t/ce_exe.$$ $menat_h_t/ce_exe.old else echo "capture was failed?" >>$menat_log echo "#$mn_time capture was failed? menat_ends" >>$cap_end_f echo >>$cap_end_f ma_ex_exp=$menat_h_t/$ce_fn_12.E$cap_dev_n.mtq fi fi fi p_ma_ex_exp=tmp/${ma_ex_exp##*/} echo "$mn_time, $ce_fn is moved to $p_ma_ex_exp." >>$menat_log mv -f $cap_end_f $ma_ex_exp;mv_v=$? if [ $mv_v != 0 ];then echo "failed, mv -f $cap_end_f $ma_ex_exp;mv_v=$mv_v" >>$menat_log return $mv_v else echo "${cap_end_f##*/} was moved to ${ma_ex_exp##*/} successfully." >>$menat_log fi rm -f $menat_h_t/*.t.db* rm -f $menat_h_t/db*prog* exe_v_tmp=`$ma_ex_exp -c exe_v` exe_v_tmp=`n_ident ${exe_v_tmp:--1} 0` if [ $exe_v_tmp -lt 0 ];then echo "exe_v_tmp is $exe_v_tmp, unexpectedly ma_exe was edited." >>$menat_log ed -s $ma_ex_exp >/dev/null 2>&1 <>$menat_log fi mn_time=`date '+%Y-%m-%d %a %H:%M'` cc_st_n=`grep -n menat_que_record\$ $ma_ex_exp|tail -n1|cut -d':' -f1` cc_ed_n=`grep -n menat_ends\$ $ma_ex_exp|tail -n1|cut -d':' -f1` if [ ! -f $menat_h_t/cc.log ];then echo "cc.log was created at $mn_time by $exe_user in $sad_version from $pp_d." >>$menat_h_t/cc.log chmod -f 664 $menat_h_t/cc.log chgrp -f menat $menat_h_t/cc.log fi cc_dd=`sed -n "${cc_st_n},${cc_ed_n:-\\\$}p" $ma_ex_exp` ed -s $menat_h_t/cc.log >/dev/null 2>&1 <>$menat_log echo "$ms_time $sad_version executed by $exe_user from $pp_d." >>$menat_log time_n=`date '+%Y%m%d%H%M'` exp_time_n=`date -d -2hour '+%Y%m%d%H%M'` men_ex_n=`ps axw --width 512|grep -v grep|grep -c 'mencoder .*-tv'` sad_lock_ex_n=18 sl_n=0 if [ -f $sad_lock ];then lock_YmdHM=`grep ^sl_time= $sad_lock|head -n1|cut -d'=' -f2` lock_Ymd=${lock_YmdHM:0:8} lock_H=${lock_YmdHM:8:2} lock_M=${lock_YmdHM:10:2} sad_lock_YmdHM=`date -d "15minute $lock_Ymd $lock_H:$lock_M" '+%Y%m%d%H%M'` dvn=`n_ident $sad_lock_YmdHM`;dvn_v=$? if [ $dvn_v != 0 ];then sad_lock_YmdHM=$time_n fi lock_pp_d=`grep ^pp_d= $sad_lock|head -n1|cut -d'=' -f2` lock_t=`grep ^sl_time= $sad_lock|head -n1|cut -d'=' -f2` p_lock_t=`p_date $lock_t` echo "$sad_version from $pp_d found sad_lock created at $p_lock_t from $lock_pp_d." >>$menat_log if [ -f $sad_lock ];then while [ -f $sad_lock ];do time_n=`date '+%Y%m%d%H%M'` if [ $time_n '>' $sad_lock_YmdHM ];then sad_lock_err=1 break else sad_lock_err=0 sl_n=$(($sl_n+1)) if [ $sl_n -lt $sad_lock_ex_n ]&&[ -f $sad_lock ];then echo "$sad_version from $pp_d was blocked by $lock_pp_d for 10s." >>$menat_log nw_lock_pp_d=`grep ^pp_d= $sad_lock|head -n1|cut -d'=' -f2` nw_lock_t=`grep ^sl_time= $sad_lock|head -n1|cut -d'=' -f2` sleep 10s if [ ! -f $sad_lock ];then break elif [ "$nw_lock_t" != "$lock_t" ];then echo "sad_lock was renewaled by $nw_lock_pp_d." >>$menat_log echo "$sad_version from $pp_d was re-blocked by $nw_lock_pp_d for 10s." >>$menat_log sad_lock_YmdHM=`date -d "15minute $lock_Ymd $lock_H:$lock_M" '+%Y%m%d%H%M'` lock_pp_d=$nw_lock_pp_d lock_t=$nw_lock_t sl_n=0 fi else sad_lock_err=2 break fi fi done else sad_lock_err=0 fi else sad_lock_err=-1 fi sl_time=`date '+%Y%m%d%H%M'` p_sl_time=`date '+%Y-%m-%d %a %H:%M:%S'` err_lock="sad_lock of $lock_pp_d" if [ $sad_lock_err = 1 ];then echo "$sad_version from $pp_d was loop over for $err_lock at $p_sl_time." >>$menat_log elif [ $sad_lock_err = 2 ];then echo "$err_lock was expired, $sad_version from $pp_d ignored sad_lock at $p_sl_time." >>$menat_log fi echo "pp_d=$pp_d" >$sad_lock echo "sl_time=$sl_time" >>$sad_lock echo "sad_lock of $sad_version from $pp_d was created at $p_sl_time." >>$menat_log if [ $men_ex_n = 0 ];then if [ -d $menat_lock ];then for t in `ls -rt $menat_lock/` ;do tt=$menat_lock/$t if [ -d $tt ];then continue fi lock_et=`grep ::end\$ $tt|tail -n1|cut -d' ' -f3` dvn=`n_ident $lock_et`;dvn_v=$? if [ ${#lock_et} != 12 ]||[ $dvn_v != 0 ]||[ ${lock_et:0:1} = 0 ];then lock_et=`ft_date $tt` fi if [ $lock_et '<' $exp_time_n ];then mv -f $tt $menat_h_t/locK.err echo "strange lock.menat/$t was found. Remove!" >>$menat_log if [ "$rm_ll" ];then rm_ll="$rm_ll,$t" else rm_ll="$t" fi lock_err=1 fi done if [ ! "`ls $menat_lock`" ];then rm -rf $menat_lock fi fi if [ "$max_nw_lock" ];then lock_err_f=${max_nw_lock##*/} else lock_err_f=locK fi if [ "$lock_err" = 1 ];then echo "unexpected lock.menat was found, why? removed it for initialization. ${rm_ll:-menat.lock} " >$menat_h_t/msd.mesg $menat_mail -vs $vs_hn -a menat -p 4 -i $lock_err_f -n $menat_h_t/msd.mesg fi lock_off=${lock_off:-2} else lock_off=${lock_off:-0} fi if [ $lock_off = 1 ];then menat_ex=0 else if [ -d $menat_lock ];then menat_ex=1 for t in $menat_lock/* ;do if [ -f $t ];then if [ "$cap_run_f" ];then cap_run_f="$cap_run_f,${t##*/}" else cap_run_f=${t##*/} fi fi done else menat_ex=0 fi fi ################################################################################## ################################################################################## if [ "$pp_d" = s ];then echo "temporal start block enabled." >>$menat_log ma_ex_ls="" elif [ "$lock_off" = 1 ];then echo "now, lock_off running." >>$menat_log cap_end_ps $menat_h/$lock_off_f cap_t="" for t in `ls $menat_lock/ 2>/dev/null` ;do if [ $t != ${pp_d%%:*} ];then cap_t="$cap_t $t" fi done echo "cap_t=$cap_t" >>$menat_log if [ "$cap_t" ];then echo "capturing $cap_t started, $sad_version from $pp_d was aborted." >>$menat_log ma_ex_ls="" else ma_ex_ls="$menat_h/*.mtq" fi else ma_ex_ls="$menat_h/*.mtq" fi pp_v=0 for ma_ex in $ma_ex_ls ;do mn_time=`date '+%Y-%m-%d %a %H:%M'` mn_YmdHM=`date '+%Y%m%d%H%M'` ma_fn=${ma_ex##*/} if [ "$menat_ex" = 1 ];then echo "now menat is capturing $cap_run_f, break." >>$menat_log break elif [ -d $menat_lock ]&&[ "$lock_off" != 1 ];then echo "capture started, aborted $sad_version from $pp_d $shutdown_no." >>$menat_log echo "cap_list: `ls $menat_lock`" >>$menat_log mv_v=1;b_n=0 while [ $mv_v != 0 ]&&[ -f $sad_lock ];do b_n=$(($b_n+1)) mv -f $sad_lock $sad_lock.$b_n;mv_v=$? done exit 0 fi ############################# if [ -d $ma_ex ];then mv -f $ma_ex $menat_h_t echo "$sad_version: error message" >$menat_h_t/msd.mesg $menat_mail -a menat -p 4 -T "Warning! removed $ma_ex" -n $menat_h_t/msd.mesg continue fi if [ ! -r $ma_ex ];then ls_unread=`ls -l $ma_ex 2>/dev/null` echo "$ma_fn is not readable." >>$menat_log if [ "$ls_unread" ];then echo "$ls_unread" >>$menat_log else echo "$ma_fn, such file or directory is not found." >>$menat_log fi echo >>$menat_log continue fi ma_fn_12=${ma_fn%.*.mtq} mtq_v=${ma_fn#*.};mtq_v=${mtq_v%.*} mtq_v1=${mtq_v:0:1} mtq_v2=${mtq_v:1:1} t_Y=${ma_fn:0:4} t_m=${ma_fn:4:2} t_d=${ma_fn:6:2} t_H=${ma_fn:8:2} t_M=${ma_fn:10:2} atq_Ymd="$t_Y-$t_m-$t_d" atq_Ymd_HM="$t_Y-$t_m-$t_d $t_H:$t_M" time_at="$t_H:$t_M $atq_Ymd" tmp_YmdHM=`date -d "$atq_Ymd ${t_H}:${t_M}" '+%Y-%m-%d %H:%M'` if [ "$tmp_YmdHM" != "$atq_Ymd ${t_H}:${t_M}" ];then time_err=1 mv -f $ma_ex $menat_h_t/$ma_fn echo "$sad_version: invalid mtq file, $ma_fn." >$menat_h_t/msd.mesg $menat_mail -a menat -p 4 -T "Warning! removed $ma_fn" -n $menat_h_t/msd.mesg continue fi week="" . $ma_ex -c 2>/dev/null cap_dev_t=$cap_dev cap_dev_t=${cap_dev_t#/dev/video} case "$cap_dev_t" in [1-3] ) cap_dev_n=$cap_dev_t ;; * ) cap_dev_n="" ;; esac to_addr=$menat_user to_addr=${to_addr:-menat} if [ $mn_YmdHM '>' "$time_e" ];then cap_end_ps $ma_ex continue fi match_job=`$ma_atq|grep "$atq_Ymd_HM"` if [ "$match_job" ];then job_n=0 for t in `echo "$match_job" | cut -f1` ;do t_cap_dev=`at -c $t |grep cap_dev= |cut -d'=' -f2` if [ $t_cap_dev = $cap_dev ];then if [ $job_n = 1 ];then atrm $t continue fi #echo ma_fn=$ma_fn prs_id="$prs_id" t=$t if [ ! "$prs_id" ];then at_add_ps "$time_at" "$ma_ex" 1;at_add_v=$? elif [ $t = $prs_id ];then job_ok=1 pp_ls="$pp_ls $ma_fn" pp_v=$(($pp_v+1)) else #### ########## ############ ed -s $ma_ex >/dev/null 2>&1 <>$menat_log echo "$ma_fn job id was revised from $prs_id to ${t}." >>$menat_log fi job_n=1 fi done continue else at_add_ps "$time_at" "$ma_ex" if [ "$prs_id" ];then re_prs_id=`$ma_ex -c prs_id` echo "unknown error, the job had been added in que, but none." >>$menat_log echo "$ma_fn job id was revised from $prs_id to $re_prs_id." >>$menat_log fi fi done i=1;ma_qi=1 while [ "$ma_qi" ]&&[ "$pp_d" != s ]&&[ $menat_ex = 0 ];do ma_id_dd=`$ma_atq|sed -n "$i"p` ma_id=`echo "$ma_id_dd"|cut -f1` #job id ma_rq=`echo "$ma_id_dd"|cut -d' ' -f3` #status of job ma_tt=`echo "$ma_id_dd"|cut -f2|cut -d' ' -f1-2` #human readable exp. 2007-03-20 02:30 ma_qi=`echo "$ma_tt"|sed 's/-//g;s/://g;s/ //g'` #12 exp. 200703200230 if [ ! "$ma_id" ]||[ ! "$ma_qi" ];then break fi if [ "$time_n" -ge "$ma_qi" ]||[ "$ma_rq" = '=' ];then i=$(($i+1)) continue fi if [ "`ls $menat_h/*.mtq`" ];then q_vv=`grep "^#$ma_id $ma_tt" $menat_h/*.mtq` else q_vv="" fi q_vv_cd=`at -c $ma_id|grep ^cap_dev=|cut -d'=' -f2` if [ ! "$q_vv" ];then if [ $exe_user = menat ];then dvn=`atrm $ma_id >/dev/null 2>&1` sudo_v="" else dvn=`sudo /bin/su - menat -c "atrm $ma_id" >/dev/null 2>&1` sudo_v="sudo /bin/su - menat -c " fi echo >>$menat_log echo "$sudo_v\"atrm $ma_id\", the book is updated by $sad_version from $pp_d." >>$menat_log echo "`date '+%Y-%m-%d %a %H:%M'`, a job at $ma_tt was removed by $exe_user." >>$menat_log if [ "`ls $menat_h_t/*.mtq`" ];then removed_org=`grep -H "^#$ma_id .* menat_que_record\$" $menat_h_t/*.mtq|cut -d':' -f1` if [ "$removed_org" ];then rm_stmp=`grep -c ' was removed ' $removed_org` end_stmp=`grep -c 'menat_ends$' $removed_org` if [ "$rm_stmp" = 0 ]&&[ "$end_stmp" = 0 ];then echo "#the job id $ma_id was removed by unknown reason." >>$removed_org echo >>$removed_org fi fi fi fi i=$(($i+1)) done ######################################################################################### ######################################################################################### ###### ####### ########### ######### ########### ###### ####### ########### ######### ########### ###### ####### ########### ######### ########### ###### ####### ########### ######### ########### ######################################################################################### ######################################################################################### p_el_time=`date '+%Y-%m-%d %a %H:%M:%S'` echo "sad_lock of $sad_version from $pp_d was removed at $p_el_time." >>$menat_log if [ ${sad_ht_exe:-0} != 0 ];then if [ -x $sad_htaccess ];then $sad_htaccess fi fi if [ ${sad_dl_rist:-0} = 1 ];then sad_dl_span=${sad_dl_span:-80} for t in `ls $menat_h/ 2>/dev/null` ;do t_dl_ext=${t##*.};t_dl_12=${t%%.*} if [ ${t_dl_ext:-0} = mtq ]&&[ ${#t_dl_12} = 12 ];then nx_cap=$t break fi done if [ "$nx_cap" ];then dl_link_dir=$user_h/public_html/menat dl_tlong=`$menat_h/$nx_cap -c time_epm` safe_dl_time=`date -d ${sad_dl_span}minutes '+%Y%m%d%H%M'` if [ $t_dl_12 '>' $safe_dl_time ];then echo "there is next job out of dl_span ${sad_dl_span}minutes, at $p_el_time." >>$menat_log dl_ok=1 if [ "`readlink $dl_link_dir`" = /dev/null ];then ln -fsn $ma_h $dl_link_dir echo "download ristriction was cancelled." >>$menat_log rm -f $menat_h_t/*.t.db* else echo "download is permitted." >>$menat_log fi if [ $http_bp_ok = 1 ];then if [ "`readlink $http_bp`" = /dev/null ];then ln -fsn $ma_bp $http_bp echo "download ristriction of bp files was cancelled." >>$menat_log else echo "download of bp files is permitted." >>$menat_log fi fi else echo "there is next job waiting for capture dl_span ${sad_dl_span}minutes, at $p_el_time." >>$menat_log dl_ok=0 if [ "`readlink $dl_link_dir`" != /dev/null ];then if [ -x "$ma_dl_ristriction" ];then $ma_dl_ristriction fi ln -fsn /dev/null $dl_link_dir if [ -x "$ma_dl_ristriction" ];then $ma_dl_ristriction fi echo "download was ristricted." >>$menat_log rm -f $menat_h_t/*.t.db* else echo "download ristriction goes on." >>$menat_log fi if [ $http_bp_ok = 1 ];then if [ "`readlink $http_bp`" != /dev/null ];then echo "download of bp files was ristricted." >>$menat_log ln -fsn /dev/null $http_bp else echo "download of bp files ristriction goes on." >>$menat_log fi fi fi else dl_ok=1 echo "there is no job at $p_el_time." >>$menat_log fi fi mv_v=1;b_n=0 while [ $mv_v != 0 ]&&[ -f $sad_lock ];do b_n=$(($b_n+1)) mv -f $sad_lock $sad_lock.$b_n;mv_v=$? done if [ "$pp_v" != 0 ];then echo >>$menat_log if [ "$pp_v" = 1 ];then echo "the following job was not changed." >>$menat_log else echo "the following jobs were not changed." >>$menat_log fi echo "${pp_ls# } at ${p_el_time%:*}." >>$menat_log fi i=1 progchk_rot=$((1440/$sleep_m)) if [ $pp_d = s ]&&[ ! -f /var/lock/subsys/menatd ]&&[ ! -f $menat_h_t/sad.loop ];then echo $time_n >$menat_h_t/sad.loop menat_lock_err=$menat_h_t/locK.err if [ -f $menat_h_t/shut_al.end ];then shut_al_mseg=`cat $menat_h_t/shut_al.end` echo "the system was shutdowned by ${shut_al_mseg:-unknown}." >>$menat_log rm -f $menat_h_t/shut_al ii=0 for t in $menat_h_t/locK.err/* ;do if [ -f $t ];then ii=$(($ii+1)) if [ $ii -le 10 ];then continue else rm -fr $t fi else continue fi done else echo "the system was not shutdowned by $sad_version." >>$menat_log if [ ! "`/sbin/pidof mencoder`" ];then reboot_YmdHM=`ft_date /` p_reboot_YmdHM=`ft_date / 1` echo "the system rebooted at $p_reboot_YmdHM." >>$menat_log lock_ls_0=`ls -td $menat_h_t/lock.* 2>/dev/null` lock_err_r="" lock_err_f="" err_n=0 for t in ${lock_ls_0:-0} ;do if [ ! -f $t ]&&[ ! -d $t ];then continue fi if [ $t = $menat_lock_err ];then continue fi tt=${t##*/} c_lm_YmdHM=`ft_date $t` if [ $c_lm_YmdHM '<' $reboot_YmdHM ];then if [ -f $menat_lock_err ];then if [ -f $menat_lock_err ];then rm -rf $menat_lock_err;rm_v=$? else rm_v=0 fi if [ $rm_v = 0 ];then mkdir $menat_lock_err else i2=0 while [ ! -d $menat_lock_err ];do if [ $i2 -gt 7 ];then echo "unknown error occured to mkdir locK.err." >>$menat_log break fi i2=$(($i2+1)) mkdir $menat_lock_err.$i2 menat_lock_err=$menat_lock_err.$i2 done fi elif [ ! -d $menat_lock_err ];then mkdir $menat_lock_err fi if [ $tt = lock.menat ];then if [ -d $t ];then for t2 in $menat_lock/* ;do echo "$p_reboot_YmdHM:err.moved:$tt:$sad_version:$pp_d" >>$t2 mv -f $t2 $menat_lock_err err_n=$(($err_n+1)) tt2=${t2##*/} if [ "$cap_f_ls" ];then cap_f_ls="$cap_f_ls,$tt2" else cap_f_ls=$tt2 lock_err_f=$menat_lock_err/$tt2 fi done rm -rf $t elif [ -f $t ];then echo "$p_reboot_YmdHM:err.moved:$tt:$sad_version:$pp_d" >>$t if [ -f $menat_lock_err/lock.menat ]||[ -d $menat_lock_err/lock.menat ];then rm -rf $menat_lock_err/lock.menat fi cap_f_ls=`cat $t|head -n1|cut -d':' -f2|cut -d' ' -f4` mv -f $t $menat_lock_err lock_err_f=$menat_lock_err/$tt err_n=$(($err_n+1)) fi down_process=capturing lock_err_r=$cap_f_ls else echo "$p_reboot_YmdHM:err.moved:$tt:$sad_version:$pp_d" >>$t mv -f $t $menat_lock_err err_n=$(($err_n+1)) if [ "$cmp_err_r" ];then cmp_err_r="$cmp_err_r.$tt" else cmp_err_r=$tt fi lock_err_f=${lock_err_f:-$menat_lock_err/$tt} down_process=${down_process:-compress} fi fi done if [ "$cap_f_ls" ];then if [ "$cmp_err_r" ];then lock_err_r="$cap_f_ls - compressing $cmp_err_r" fi else if [ "$lock_ls_0" ];then lock_err_r=$cmp_err_r else lock_err_r="" fi fi if [ $err_n = 0 ]||[ $err_n = 1 ];then pre_msg="it was" else pre_msg="they were" fi if [ "$lock_err_r" ];then echo "mail message: this system might be down on $down_process of $lock_err_r? strange lock.menat remained. $pre_msg removed for initialization. $lock_err_r $menat_mail -vs $vs_hn -a menat -p 4 -i $lock_err_f -n $menat_h_t/msd.mesg " >>$menat_log echo "this system might be down on $down_process of $lock_err_r? strange lock.menat remained. $pre_msg removed for initialization. $lock_err_r ">$menat_h_t/msd.mesg mail_rv=`$menat_mail -vs $vs_hn -a menat -p 4 -i $lock_err_f -n $menat_h_t/msd.mesg` fi else echo "mencoder running now, maybe unexpectedly." >>$menat_log fi fi while [ loop ];do if [ $(($i%$progchk_rot)) = 1 ];then if [ "$prog_chk" != 0 ]&&[ -f $menat_iepg/ch.list ];then echo "$sad_version: prog_chk start for $prog_chk." >>$menat_log for t in $prog_chk ;do vs_chk=`echo "$vs_ls"|grep -c $t` if [ $vs_chk != 0 ];then dvn=`$menat_progchk -v $t 2>&1`;progchk_v=$? if [ $progchk_v != 0 ];then echo "unknown prog_chk_err occured." >>$menat_log echo "$dvn" >>$menat_log fi else echo "$sad_version: $t is invalid vs_hn." >>$menat_log continue fi done fi t_mtq_n=`ls $menat_h_t/*.mtq|wc -l` if [ ${t_mtq_n:-0} -gt $(($t_mtq_mx*2)) ];then echo "The trash files were over $((2*$t_mtq_mx)). $sad_version cleaned up the trash directory automatically, $menat_h_t. " >$menat_h_t/msd.mesg echo "$sad_version: trash file is over $((2*$t_mtq_mx))." >>$menat_log echo "$sad_version: clean up the trash directory automatically at $pn_time." >>$menat_log rm_f_n=0 for t in `ls -rtd $menat_h_t/*mtq` ;do rm_bfn=`$t -c bfn` rm_bfn_b=${rm_bfn%.*} rm_bfn_ls=`ls $ma_h/$rm_bfn_b.*`;ls_rv=$? if [ $ls_rv = 0 ];then continue else rm -f $t;rm_v=$? fi if [ $rm_v != 0 ];then echo "$sad_version: rm $t was failed." >>$menat_log else rm_f_n=$(($rm_f_n+1)) fi if [ $rm_f_n -gt $t_mtq_mx ];then break fi done mail_subj="Clean Up Trash on $vs_hn!" $menat_mail -vs $vs_hn -a menat -p 5 -T "$mail_subj" -n $menat_h_t/msd.mesg elif [ ${t_mtq_n:-0} -gt $t_mtq_mx ];then echo "The trash files were over $t_mtq_mx. Empty the directory, $menat_h_t. " >$menat_h_t/msd.mesg mail_subj="Empty Trash on $vs_hn!" $menat_mail -vs $vs_hn -a menat -p 4 -T "$mail_subj" -n $menat_h_t/msd.mesg fi fi echo >>$menat_log if [ $exe_user != root ]&&[ $exe_user != menat ];then break fi sm=${sleep_m}m if [ $i != 1 ];then echo "`date '+%Y-%m-%d %a %H:%M'` sleep loop NO.$i start, now in $sm sleeping." >>$menat_log sleep $sm LOOP="LOOP.$i" else LOOP=start fi i=$(($i+1)) t_12_nxt="" nx_cap_mtq="" t_12_YmdHM=`date '+%Y%m%d%H%M'` t_12_5m=`date -d "5minutes" '+%Y%m%d%H%M'` nx_force_sad=0 for t in `ls $menat_h` ;do t_12=${t%.*.mtq} t_pr_n=${t%.mtq};t_pr_n=${t_pr_n#*.} t_12_nxt=`n_ident $t_12`;n_v=$? if [ ${#t_12_nxt} = 12 ]&&[ $n_v = 0 ];then if [ ${t_pr_n:0:1} = n ];then nx_force_sad=1 nx_un_pr_f=$t continue fi nx_cap_mtq=$t nx_c_exe=$menat_h/$t break else t_12_nxt="" fi done if [ ! "$t_12_nxt" ];then shut_v=`$menat_sad $LOOP` elif [ ${t_12_YmdHM:-0} '>' "`$nx_c_exe -c time_e`" ];then shut_v=`$menat_sad $LOOP` echo "$sad_version: unexpected mtq file, $t exsits." >>$menat_log echo "$sad_version: menat_sad finished in $LOOP." >>$menat_log elif [ ${t_12_YmdHM:-0} '>' ${t_12_nxt:-0} ];then shut_v=`$menat_sad $LOOP` echo "$sad_version: $t may be running." >>$menat_log echo "$sad_version: menat_sad finished in $LOOP." >>$menat_log else if [ ${t_12_nxt:-0} '>' ${t_12_5m:-0} ];then shut_v=`$menat_sad $LOOP`;r_shut_v=$? if [ $r_shut_v != 0 ];then echo >>$menat_log echo "$sad_version: menat_sad error occured by $r_shut_v." >>$menat_log fi echo "$sad_version: menat_sad finished in $LOOP." >>$menat_log else echo "$sad_version: [ t_12_nxt=${t_12_nxt:-0} '>' t_12_5m=${t_12_5m:-0} ]" >>$menat_log if [ "$nx_cap_mtq" ];then echo "$sad_version: next capture, $nx_cap_mtq is soon, suspend $LOOP." >>$menat_log else echo "$sad_version: unknown nx_cap_mtq exists, suspend $LOOP." >>$menat_log fi if [ "$nx_force_sad" = 1 ];then echo "$sad_version: but nx_un_pr_f=$nx_un_pr_f exists, force to menat_sad." >>$menat_log shut_v=`$menat_sad $LOOP` else shut_v="suspend $LOOP" fi fi fi if [ "$shut_v" = shutdown ];then echo "$sad_version $LOOP end." >>$menat_log echo '*******************************************************' >>$menat_log echo >>$menat_log rm -f $menat_h_t/sad.loop exit 0 elif [ "$shut_v" = in_shutdown ];then echo "NOW in shutdown process. $sad_version in $LOOP, loop out." >>$menat_log echo >>$menat_log rm -f $menat_h_t/sad.loop exit 0 fi done else if [ ! -f $menat_lock ]&&[ ! -d $menat_lock ] ;then for t_t in $menat_h_t/lock.* ;do if [ ! -f "$t_t" ];then continue fi ex_time=`date -d -2hour '+%Y%m%d%H%M'` lk_tYmdHM=`ft_date $t_t` rm_lock_ok=0 cmp_fnb=${t_t##*/};org_fnbb=${cmp_fnb#lock.} menv=`ps axwu --width 512 |grep -v grep|grep -c $org_fnbb` if [ $menv = 0 ]&&[ $ex_time '>' $lk_tYmdHM ];then dvn=`rm -f $t_t 2>&1`;rm_v=$? if [ $rm_v != 0 ];then echo "rm -f ${t_t##*/}, error occured." >>$menat_log echo "$dvn" >>$menat_log err_rm_v=$rm_v rm_lock_ok=0 else for t in `ls $menat_h_t/db*prog* >/dev/null 2>&1` ;do dvn=`rm -f $t 2>&1`;rm_v=$? if [ $rm_v != 0 ];then echo "rm -f ${t##*/}, error occured." >>$menat_log echo "$dvn" >>$menat_log fi done rm_lock_ok=1 fi echo >>$menat_log echo "`date '+%Y-%m-%d %a %H:%M'`, maybe compress error occured." >>$menat_log if [ $rm_lock_ok = 1 ];then echo "time expired, ${t_t##*/} was removed by $exe_user." >>$menat_log else echo "time expired, but rm ${t_t##*/} was failed by $err_rm_v." >>$menat_log fi fi done fi cl_Ymd=`head -n 1 $menat_log|cut -d' ' -f5|sed 's/-//g'` dvn=`n_ident $cl_Ymd`;dvn_v=$? if [ ${#cl_Ymd} != 8 ]||[ $dvn_v != 0 ];then if [ `du -k $menat_log 2>/dev/null |cut -f1` -gt 1024 ];then cl_Ymd=`date -d -10day '+%Y%m%d'` else cl_Ymd=`date '+%Y%m%d'` fi fi if [ `date -d -7day '+%Y%m%d'` '>' "$cl_Ymd" ];then mv -f $menat_log ${menat_log}.1 echo "new log started at `date '+%Y-%m-%d %a %H:%M'` by $exe_user in $pp_d." >$menat_log if [ $exe_user = root ];then dvn=`chown -f menat.menat $menat_log >/dev/null 2>&1` dvn=`chmod -f 664 $menat_log >/dev/null 2>&1` fi fi if [ $shutdown_ok = 1 ];then echo >>$menat_log echo "`date '+%Y-%m-%d %a %H:%M'`, menat_sd was executed by $exe_user from $pp_d." >>$menat_log shut_v=`menat_sd $pp_d` if [ "$shut_v" ];then echo "$shut_v" fi exit 0 fi fi exit 0 ########################## ########################## ## 2005-10-29 Sat 06:00 0.9.16-pre4 t_mtq_mx mail information was implemented. ## 2005-05-27 Fri 20:00 0.9.6-rc6 exe_v was implemented. ## 2005-05-25 Wed 20:00 0.9.6-rc1 atrm check routine was rivised. ## 2005-05-25 Wed 20:00 0.9.6-rc1 sad_lock was implemented. ## 2005-05-23 Mon 18:08 0.9.6-pre3 time_out was implemented. ## 2005-05-19 Thu 01:00 0.9.5-rc6 new ls compatibility. ## 2005-04-26 Tue 05:29 0.9.4-pre1 tcp lock was implemented. ## 2005-04-20 Wed 15:57 0.9.2 stable version was released. ## 2005-04-15 Fri 02:52 0.9.2-pre4 conf file safty was implemented. ## 2005-04-10 Sun 10:02 0.9.2-pre3 lock_off bug was fixed and cc.log order was changed. ## 2005-04-05 Tue 15:42 0.9.2-pre1 today's job order was revised. ## 2005-04-04 Mon 08:42 0.9.0 stable version for coming menat-0.5.6 series. ## 2005-03-30 Wed 14:15 0.8.17 rpm version stump was added. ## 2005-03-28 Mon 01:18 0.8.14 sad.loop and progchk_rot were implemented. ## 2005-03-27 Sun 03:29 0.8.10 cmp shutdown bug was fixed. ## 2005-03-23 Thu 06:53 0.8.2 cc.log was implemented. ## 2005-03-23 Thu 06:53 0.8.0 record format was revised. ## 2005-03-09 Wed 04:42 0.7.14 shutdown process was revised to remove all temporal file. ## 2005-03-07 Mon 14:05 0.7.13 web.cgi db consistency was revised. ## 2005-02-25 Fri 01:58 0.7.4 prog_chk was implemented. ## 2005-02-25 Fri 01:58 0.7.0-pre2 mtq extension was added,blunch starts. ## 2005-02-23 Wed 20:50 0.6.0-pre2 first 0.6 series,log rotation was revised. ## 2005-02-19 Sat 20:52 0.5.8 many log expressions were revised for the stable release. ## 2005-02-08 Tue 18:32 0.5.6 "shtd" URI was revised,and log_chk was implemented. ## 2005-02-06 Sun 20:02 0.5.3 menat sudo verboseness was revised. ## 2005-02-05 Sat 22:02 0.5.2 http last access time expir lock bug was fixed. ## 2005-02-02 Wed 20:44 0.5.1b first official release.