[mythtv-users] simple shutdown script

George Nassas gnassas at mac.com
Thu Jul 27 15:45:50 UTC 2006


On 27-Jul-06, at 7:19 AM, Tim Plessers wrote:

> I would
> like to create a cronjob-script that shuts down the box after 1 am,  
> ONLY
> when no more recordings are scheduled untill 5pm (when it starts up
> again).  If recordings were found, it will do the check again after  
> one
> hour, etc.

The script below should work for your purposes. I didn't actually try  
it so there may be a misspelling here or there but the concept is  
correct. Try each of the $() commands in a shell. The one thing you  
missed was checking if myth was recording, it would be nasty to shut  
down in the middle of that!

A comment on the ps you had:

> ((ps -ef | grep mplayer) returns nothing))

this will never return nothing since the "grep mplayer" will show up  
in the ps list and match itself. You have to do a grep -v grep to  
correct for that and also add something to get rid of ps headings.  
Better to use gnu ps's -C option to show only the proc you want.

I'd set up cron to run this every hour from 1am to 4pm, if the  
machine is off it won't matter and when the machine is on it does  
what you're looking for.

- George

#!/bin/bash

MythBusy=$(mythshutdown --status || echo Busy)

RecPending=$(mysql -s -u mythtv -pmythtv mythconverg <<EOF
select 'Pending' from dual
where exists (select *
               from recordmatch
               where date(starttime - interval '17' hour) = date(now 
() - interval '17' hour));
EOF
)

MPlayerProcs=$(ps --no-headers -C mplayer)

if [[ -z $MythBusy && -z $RecPending && -z $MPlayerProcs ]]; then
     shutdown -h now
fi



More information about the mythtv-users mailing list