MythTVP5K operation
Jump to navigation
Jump to search
mythCheck.sh
#!/bin/bash typeset -i PROCESSES=`ps -e |grep mythfrontend|awk '{ if(match($0,"mythfrontend")>0){ x++ } if(match($0,"grep")>0){ y++ } }END{ if(x==""){x=0;} if(y==""){y=0;} print x-y }'` if [ $PROCESSES == 0 ]; then #echo shutdown exit 0; else #echo do not shutdown exit 1; fi exit 0;
mythDoShut.sh
#!/bin/bash echo test > /tmp/run3.txt get_process_count(){ typeset -i PROCESS_CNT=`ps -e |grep $1 |awk -v process_name=$1 '{ if( match($0,process_name)>0 ) { x++ } if( match($0,"grep")>0 ){ y++ } }END{ if(x==""){x=0;} if(y==""){y=0;} print x-y }'` return $PROCESS_CNT } get_process_count "gnome-session" typeset -i PROCESSES=$? get_process_count "kdesktop" PROCESSES=$PROCESSES+$? #07:34:24 up 57 min, 2 users, load average: 0.04, 0.03, 0.00 #07:56:42 up 1:19, 2 users, load average: 0.00, 0.02, 0.00 UPTIME=`uptime` typeset -i UPTOTALMINUTES=`echo $UPTIME |awk '{ if( $0 ~ /min/ ){ min=$3 hours=0 total=hours*60+min }else{ endtime=index($3,",") tmptime=substr($3,1,endtime-1) split(tmptime,timeArray,":") min=timeArray[2] hours=timeArray[1] total=min+(hours*60) } }END{print total}'` if [ $UPTOTALMINUTES -lt 5 ]; then #echo no shutdown machine if UPTIME is less than 5min #only shutdown mythbackend /sbin/service mythbackend stop&> /tmp/run exit 1; fi if [ $PROCESSES == 0 ]; then #echo shutdown machine shutdown -h 0 exit 0; else #echo do not shutdown machine #only shutdown mythbackend /sbin/service mythbackend stop& >/tmp/run1 exit 1; fi exit 0;
mythfrontend
#In sudoers require: #disable requiretty #Cmnd_Alias MYTHTV = /sbin/service mythbackend stop, /sbin/service mythbackend start #ALL ALL=(ALL) NOPASSWD: MYTHTV sudo /sbin/service mythbackend start& >>/tmp/mythfrontend sleep 5 nohup /usr/bin/mythfrontend.bin >>/tmp/mythfrontend
mythSetTime.sh
alarmdate=`date -d "1970-01-01 $1 seconds" +"%Y-%m-%d %T"` echo $alarmdate > /proc/acpi/alarm atdate=`date -d "1970-01-01 UTC $1 seconds" +"%Y%m%d%H%M"` lastAlarm=`tail -1 /tmp/alarm.txt` lastTime=`echo $lastAlarm |awk '{print $NF}'` if [ "$lastTime" = "$atdate" ]; then echo "AT Job $lastTime exists for $atdate" > /tmp/alarm.txt else `echo "sudo /sbin/service mythbackend start& >>/tmp/mythfrontend" | at -t $atdate` echo "create AT Job for $ataDate" > /tmp/alarm.txt fi echo $1 >> /tmp/alarm.txt echo $alarmdate >> /tmp/alarm.txt echo $atdate >> /tmp/alarm.txt echo "sudo /sbin/service mythbackend start& >>/tmp/mythfrontend | at -t $atdate" >> /tmp/alarm.txt