Jump to content

Issue with my bash script


Recommended Posts

Okay, forgive me I'm bit of a hack. I have a mythtv box running on Fedora and I wrote a script to kill the frontend and to turn off my monitor. I found two separate scripts that each worked independently and I've tried merging the two together but it's not working as planned. The monitor will shut off but the script exits without killing the frontend. The frontend is the GUI that allows you to select what you want to do on myth. The reason I want to kill the frontend on shutoff is so the TV won't still be recording while gone (WAF).

 

I'm posting the original scripts and the merged script.

Original:

#!/bin/bash
PROG=mythfrontend
STATUS=`ps -e | grep $PROG | grep -v grep | wc -l | awk '{print $1}'`

if [ `echo $DISPLAY | grep -c ":0"` -ge 1 ]
then
    if [ $STATUS -eq 0 ]
    then

        ( $PROG -d & )
touch /video/mytharchive/mythtemp/mythpowerbutton-on;
    else

        if [ -a /video/mytharchive/mythtemp/mythpowerbutton-off ]
        then
                touch /video/mytharchive/mythtemp/mythpowerbutton-on;
                exit;
        else
                touch /video/mytharchive/mythtemp/mythpowerbutton-off;
                sleep 3;
                if [ -a /video/mytharchive/mythtemp/mythpowerbutton-on ]
                then
	    
                    rm -rf /video/mytharchive/mythtemp/mythpowerbutton-o* && killall $PROG
                fi
                rm -rf /video/mytharchive/mythtemp/mythpowerbutton-o*
        fi
        rm -rf /video/mytharchive/mythtemp/mythpowerbutton-o*
    fi
fi
exit 0

 

Merged:

#!/bin/bash
PROG=mythfrontend
STATUS=`ps -e | grep $PROG | grep -v grep | wc -l | awk '{print $1}'` #frontend running variable
STATUS2=`xset -q | grep "Monitor is" | awk '{print $3}'` #screen on variable

if [ "${STATUS2}" = "On" ]
then
   xset dpms force off
if [ `echo $DISPLAY | grep -c ":0"` -ge 1 ]
then
    if [ $STATUS -eq 0 ]
    then

        ( $PROG -d & )
touch /video/mytharchive/mythtemp/mythpowerbutton-on;
    else

        if [ -a /video/mytharchive/mythtemp/mythpowerbutton-off ]
        then
                touch /video/mytharchive/mythtemp/mythpowerbutton-on;
                exit;
        else
                touch /video/mytharchive/mythtemp/mythpowerbutton-off;
                sleep 3;
                if [ -a /video/mytharchive/mythtemp/mythpowerbutton-on ]
                then
	    
                    rm -rf /video/mytharchive/mythtemp/mythpowerbutton-o* && killall $PROG
                fi
                rm -rf /video/mytharchive/mythtemp/mythpowerbutton-o*
        fi
        rm -rf /video/mytharchive/mythtemp/mythpowerbutton-o*
    fi
fi
else
   xset dpms force on
if [ `echo $DISPLAY | grep -c ":0"` -ge 1 ]
then
    if [ $STATUS -eq 0 ]
    then

        ( $PROG -d & )
touch /video/mytharchive/mythtemp/mythpowerbutton-on;
    else

        if [ -a /video/mytharchive/mythtemp/mythpowerbutton-off ]
        then
                touch /video/mytharchive/mythtemp/mythpowerbutton-on;
                exit;
        else
                touch /video/mytharchive/mythtemp/mythpowerbutton-off;
                sleep 3;
                if [ -a /video/mytharchive/mythtemp/mythpowerbutton-on ]
                then
	    
                    rm -rf /video/mytharchive/mythtemp/mythpowerbutton-o* && killall $PROG
                fi
                rm -rf /video/mytharchive/mythtemp/mythpowerbutton-o*
        fi
        rm -rf /video/mytharchive/mythtemp/mythpowerbutton-o*
    fi
fi
fi



exit 0;

 

Can someone tell me what I'm doing wrong?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.