LinHES Forums
http://forums.linhes.org/

script for running mythfilldatabase when not recording
http://forums.linhes.org/viewtopic.php?f=5&t=15322
Page 1 of 2

Author:  imstr8trippin [ Tue May 22, 2007 9:14 pm ]
Post subject:  script for running mythfilldatabase when not recording

check it out...let me know what you think! i let it run if LiveTV is recording because i don't really care if it stutters. its the scheduled recordings that i am concerned about...nothing worse than looking forward to watching something you've recorded and then seeing that Myth dropped frames due to filldatabase running! well, there are probobly worse things in life, but it is pretty damn annoying!

Code:
#!/bin/sh
# --------------------------------------------------------------------
# Very simple script to execute mythfilldatabase only if there are no
# scheduled recordings currently being recorded.

# Written by:   Neil Loknath
# Date:         May 22 2007
#---------------------------------------------------------------------

# initalize variables
script='MFDB:'
db='mythconverg'


# substitute the username you want to you use to connect to mySQL
user='root'

# password variable is here, but I haven't used it
password=''
mfdb='mythfilldatabase --quiet'

# run SQL
data=`mysql $db -u $user -e "select count(*) from recorded where timediff(now(),endtime)<'00:00:00' and recgroup!='LiveTV';" -sN`

if [ $data -ge 1 ]; then
        echo "$script MythTV is currently recording a scheduled program.  Please run mythfilldatabase at another time."
else
        echo "$script MythTV will now run $mfdb"
        $mfdb
fi

exit 0

Author:  spideyk21 [ Wed May 23, 2007 5:57 am ]
Post subject: 

Nice script. I was looking to write something just like this for a mythbackup. cron job Now I have something to reference.

I just need to add something in there about checking for future recording that may happen in the next 0-30minutes. This will make sure that when the script is doing its thing there are no recording to be found.

Author:  imstr8trippin [ Wed May 23, 2007 8:49 am ]
Post subject: 

that's a good idea. i'll have to add the check for future recordings, as well.

Author:  rando [ Wed May 23, 2007 8:50 am ]
Post subject: 

Spidey, if/when you add the code to look for upcoming recordings would you mind posting it here? I'd like to add this to my system and your addition sounds like a good one.

Author:  imstr8trippin [ Wed May 23, 2007 10:52 am ]
Post subject: 

Here is an update...hasn't been fully tested, but I think this should work:

Code:
#!/bin/sh
# --------------------------------------------------------------------
# Very simple script to execute mythfilldatabase only if there are no
# scheduled recordings currently being recorded.

# Written by:   Neil Loknath
# Date:         May 22 2007
#---------------------------------------------------------------------

# initalize variables
script='MFDB:'
db='mythconverg'


# substitute the username you want to you use to connect to mySQL
user='root'

# password variable is here, but I haven't used it
password=''
mfdb='mythfilldatabase --quiet'

# run SQL
data1=`mysql $db -u $user -e "select count(*) from recorded where timediff(now(),endtime)<'00:00:00' and recgroup!='LiveTV';" -sN`
data2=`mysql $db -u $user -e "select count(*) from record where inactive=0 and (type!=0 or type!=8) and timediff(now(),concat(startdate,' ',starttime))<'00:30:00';" -sN`

if [ $data1 -ge 1 -o $data2 -ge 1 ]; then
        echo "$script MythTV is/will be recording a scheduled program.  Please run mythfilldatabase at another time."
else
        echo "$script MythTV will now run $mfdb"
        $mfdb
fi

exit 0

Author:  Gnarl [ Wed May 23, 2007 1:19 pm ]
Post subject: 

I was happy to see this script. Although running mythfilldatabase while recording isn't an issue for me, forgetting to check whether there was activity on the box before I rebooted was. I modified the above script to suit my needs.
Code:
#!/bin/sh

# initalize variables
db='mythconverg'
data0=0
data1=0
data2=0

# substitute the username you want to you use to connect to mySQL
user='root'

# password variable is here, but I haven't used it
password=''

# run SQL
data0=`mysql $db -u $user -e "select count(*) from inuseprograms where recusage like 'player'" -sN`
data1=`mysql $db -u $user -e "select count(*) from inuseprograms where recusage like 'recorder'" -sN`
data2=`mysql $db -u $user -e "select count(*) from record where inactive=0 and (type!=0 or type!=8) and timediff(now(),concat(startdate,' '$

if [ $data0 -ge 1 -o $data1 -ge 1 -o $data2 -ge 1 ]; then
        echo -e "\033[31m         WARNING!!!"
        echo -e "\033[0mMythTV is watching $data0 program(s)"
        echo "MythTV is recording $data1 program(s)"
        echo "MythTV is scheduled $data2 program(s) within 10 minutes";
        echo -e "\nDo you still wish to reboot? (y/n)"
        read ANSW
        case $ANSW in
         y) reboot ;;
         *) exit 0
        esac
else
        echo "Rebooting"
        reboot
fi

exit 0
I've also created an alias for this to the reboot command to idiot-proof rebooting against myself

Author:  tjc [ Wed May 23, 2007 6:07 pm ]
Post subject: 

Brilliant work guys. I'll be adding this to my wrapper scripts for mythfilldatabase. Something like this has been on my ToDo list for a couple months now. I may even turn it into a generic safety check to be used with various things...

Author:  Too Many Secrets [ Wed May 23, 2007 7:50 pm ]
Post subject: 

how about something along these lines applied to the "backup:, so you don't kill the BE just before your scheduled to record? would it be hard to adapt?

Author:  Gnarl [ Wed May 23, 2007 8:19 pm ]
Post subject: 

I've found an issue where recording in the next 10 minutes aren't being reported properly. It seems that when I rescheduled a show it then came up in as being recorded in the next 10 minutes. It has something to do with the time until the next recording being a negative number. I'll investigate more tomorrow.

Author:  Gnarl [ Wed May 23, 2007 8:35 pm ]
Post subject: 

Found it:
Code:
#!/bin/sh

# initalize variables
db='mythconverg'
user='root'
password=''

data0=`mysql $db -u $user -e "select count(*) from inuseprograms where recusage like 'player'" -sN`
data1=`mysql $db -u $user -e "select count(*) from inuseprograms where recusage like 'recorder'" -sN`
data2=`mysql $db -u $user -e "select count(*) from record \
        where inactive=0 and (type!=0 or type!=8) and \
        timediff(sysdate(),concat(startdate,' ',starttime))<'00:10:00' and \
        timediff(concat(startdate,' ',starttime),sysdate())<'00:10:00';\
        " -sN`

if [ $data0 -ge 1 -o $data1 -ge 1 -o $data2 -ge 1 ]; then
        echo -e "\033[31m\n         WARNING!!!\033[0m\n"
        if [ $data0 -ge 1 ]; then
                echo "MythTV is watching $data0 program(s)"
        fi
        if [ $data1 -ge 1 ]; then
                echo "MythTV is recording $data1 program(s)"
        fi
        if [ $data2 -ge 1 ]; then
                echo "MythTV has scheduled $data2 program(s) within 10 minutes"
        fi
        echo -e "\nDo you still wish to reboot? (y/n)"
        read ANSW
        case $ANSW in
         y) reboot ;;
         *) exit 0
        esac
else
        echo "Rebooting"
        reboot
fi

exit 0

Edit: Prettied it up

Author:  imstr8trippin [ Wed May 23, 2007 10:04 pm ]
Post subject: 

gnarl, can you describe again exactly how to re-create the problem? i dont quite understand what happened?

Author:  Gnarl [ Thu May 24, 2007 7:08 am ]
Post subject: 

Try making a new schedule to record something right now. When I tried that, the new schedule show in the script as being recorded within the next 10 minutes.

When I troubleshot the script, the timediff() had a result of eg -03:21:00 hours which is less then 10 minutes.

Author:  imstr8trippin [ Thu May 24, 2007 8:55 am ]
Post subject: 

ok thanks...i see the problem and, potentially, another one. it looks like the startdate in the record table is always the date of the first recording in a series of recordings (ex. weekly, daily, etc.) i'll post some new code when i get the chance.

Author:  Gnarl [ Thu May 24, 2007 9:25 am ]
Post subject: 

Too Many Secrets wrote:
how about something along these lines applied to the "backup:, so you don't kill the BE just before your scheduled to record? would it be hard to adapt?
I don't think this should be too hard to incorporate into the backup, but in the mean time you can make your own hack by replacing reboot with mythbackup in the script and creating an alias

BUT... this may create problems running mythbackup from the frontend interface. A 5 second timeout may be necessary.

Author:  Gnarl [ Thu May 24, 2007 10:09 am ]
Post subject: 

Gnarl wrote:
BUT... this may create problems running mythbackup from the frontend interface. A 5 second timeout may be necessary.
Another way i found to solve this is to alias command for use on the command line and use the absolute path to the command in the frontend. But of course this does bypass the checks

Page 1 of 2 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/