MythTVP5K operation

From LinuxTVWiki
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