View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 5 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Thu Dec 20, 2007 6:18 pm 
Offline
Joined: Wed Jun 14, 2006 5:47 pm
Posts: 29
Location: Cleveland, Ohio
I found some scripts on another forum that I found useful, so I thought I would post them here.

The fist one will search through the tv directory and remove any recordings that are 0 bytes from the directory and database.

Code:
#!/bin/bash

RECORDINGDIR="/myth/tv"
MYSQLUSER="mythtv"
MYSQLPASS="mythtv"
SQLSCRIPT="/tmp/remove_zero_byte_recordings.sql"

# Create empty file or remove one that already exists
cp /dev/null $SQLSCRIPT

# Search for files ending in ".mpg"
for filename in `ls -1 $RECORDINGDIR | grep -i "mpg$"`
do
    # See if they are more than 0 bytes
    if [ ! -s "${RECORDINGDIR}/${filename}" ]
    then
       # Delete the file and add the delete query to the sql script
       echo "$filename is 0 bytes"
       rm -f "${RECORDINGDIR}/${filename}"
   rm -f "${RECORDINGDIR}/${filename}.png"
       echo "DELETE FROM recorded WHERE basename = '$filename';" >> $SQLSCRIPT
    fi
done

# Execute the SQL to remove database entries
mysql -u $MYSQLUSER -p$MYSQLPASS mythconverg < $SQLSCRIPT
# Clean up the tmp file
rm -f $SQLSCRIPT


The second will remove files in the tv directory that have no associated record in the database.

Code:
#!/bin/bash

# remove files in the tv storage directory that are not in the database

RECORDINGDIR="/myth/tv"
SQLSCRIPT="/tmp/remove_zero_byte_recordings.sql"

# Search for files ending in ".mpg"
for filename in `ls -1 $RECORDINGDIR | grep -i "mpg$"`
do
    ROWS=`mysql --batch  -e "SELECT count(basename) FROM recorded WHERE basename = '$filename'" mythconverg | tail -1`
    echo "Found $ROWS matching $filename"

    if [ $ROWS -eq 0 ]
    then
        rm -f $RECORDINGDIR/$filename
   echo "$RECORDINGDIR/$filename"
    fi

done


The last one will remove database entries that have no file associated with them.


Code:
#!/bin/bash
# remove database listings that have no file associated with them
#
RECORDINGDIR="/myth/tv"
MYSQLUSER="mythtv"
MYSQLPASS="mythtv"
SQLSCRIPT="/tmp/remove_zero_byte_recordings.sql"
#
# Create empty file or remove one that already exists
echo " " > $SQLSCRIPT
#
# Create a list of filenames from the database and parse them
#
for filename in `mysql --batch  -e "SELECT basename FROM recorded ORDER BY basename" mythconverg`
do
    echo "record is $filename"
    # See if the file exists
    if [ ! -s "${RECORDINGDIR}/${filename}" ]
    then
        # Add the delete query to the sql script
        echo "$filename does not exist in $RECORDINGDIR"
        echo "DELETE FROM mythconverg.recorded WHERE basename = '$filename';" >> $SQLSCRIPT
    fi
done
#
# Execute the SQL to remove database entries
mysql -u $MYSQLUSER -p$MYSQLPASS mythconverg < $SQLSCRIPT
#
# Clean up the tmp file
rm -f $SQLSCRIPT


The last one removed a lot of left-over junk from my database.


Last edited by derek1234 on Sun Dec 23, 2007 5:50 pm, edited 1 time in total.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 20, 2007 9:08 pm 
Offline
Joined: Mon Mar 13, 2006 2:28 am
Posts: 143
Location: Brisbane, Australia
Howdy,

Great ideas from the original author, but a couple of issues.

First script has a typo, third last line should read;

Code:
mysql -u $MYSQLUSER -p$MYSQLPASS mythconverg < $SQLSCRIPT


Second script I was having trouble with due to permission errors with the way it was accessing the DB, so I rewrote it to be more like the others.

Code:
#!/bin/bash

# remove files in the tv storage directory that are not in the database

RECORDINGDIR="/myth/tv"
MYSQLUSER="mythtv"
MYSQLPASS="mythtv"
SQLSCRIPT="/tmp/remove_recordings_without_db_entry.sql"

# Create empty file or remove one that already exists
cp /dev/null $SQLSCRIPT

# Search for files ending in ".mpg"
for filename in `ls -1 $RECORDINGDIR | grep -i "mpg$"`
do
        echo "SELECT count(basename) FROM recorded WHERE basename = '$filename';" > $SQLSCRIPT
        ROWS=$(mysql -u $MYSQLUSER -p$MYSQLPASS --batch mythconverg < $SQLSCRIPT |tail -1)

        if [ $ROWS -eq 0 ]
        then
                rm -f $RECORDINGDIR/$filename
                echo "Removing $RECORDINGDIR/$filename"
        fi
done

# Clean up the tmp file
rm -f $SQLSCRIPT



Third script. The reason it cleans up so much is because the database stores everything you've recorded. From what I gather this is so it doesn't record repeats, etc of shows you've previously recorded even if they have been deleted from your hard drive. I'm fairly certain that's why you get the "Delete It, but allow it to rerecord" box, whereas if you just delete it it won't rerecord. Someone else may be able to clarify.

Regards,
Kirk.

_________________
MBE/FE ~ R5F27 ~ Asus A8N-VM-CSM ~ AMD64 3500+ ~ 1GB RAM ~ 1.5TB Storage ~ Nova-T-500 ~ SH-S183A DVDRW ~ LC20M Case ~ iMON-Pad Remote
FE ~ Diskless ~ Asus M2NPV-VM ~ AMD X2 BE-2350 (45w) ~ 1GB RAM ~ TT Lanbox Lite ~ iMON-Pad Remote


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 23, 2007 6:15 pm 
Offline
Joined: Wed Jun 14, 2006 5:47 pm
Posts: 29
Location: Cleveland, Ohio
I corrected the error in the first script. That was a good catch since it would not have given an error.

Quote:
Third script. The reason it cleans up so much is because the database stores everything you've recorded. From what I gather this is so it doesn't record repeats, etc of shows you've previously recorded even if they have been deleted from your hard drive. I'm fairly certain that's why you get the "Delete It, but allow it to rerecord" box, whereas if you just delete it it won't rerecord. Someone else may be able to clarify.


I think the info your referring to is in the "oldrecoreded" table. When I browse through that table there is a record for every program recorded since my last re-install.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 23, 2007 7:10 pm 
Offline
Joined: Mon Mar 13, 2006 2:28 am
Posts: 143
Location: Brisbane, Australia
Ah, that's the one. Thanks for clearing that up.

_________________
MBE/FE ~ R5F27 ~ Asus A8N-VM-CSM ~ AMD64 3500+ ~ 1GB RAM ~ 1.5TB Storage ~ Nova-T-500 ~ SH-S183A DVDRW ~ LC20M Case ~ iMON-Pad Remote
FE ~ Diskless ~ Asus M2NPV-VM ~ AMD X2 BE-2350 (45w) ~ 1GB RAM ~ TT Lanbox Lite ~ iMON-Pad Remote


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 12:59 pm 
Offline
Joined: Sun Nov 13, 2005 5:56 pm
Posts: 104
Thanks! I love these scripts.
I'll have to compare these 3 to the dead_wood.sh from another thread to see the overlap but I like to have choices!

-s-


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu