Unfortunately no one can be told what fun_plug is - you have to see it for yourself.
You are not logged in.
im trying to write a small script to unpack mostly movies, and delete the rar files when its done, but sometimes
the unraring fails or it skips for some reason, and then i dont want the rar files to be deleted, so the script should
check if the current directory holds any files besides *.rar or *.r01 or *.part.01.rar so if there exits an *.avi file
there it should b safe to delete the rar files, or an *.mpg or *.mkv..
so this wasnt so easy as i first thought i found a script that checks for rar files with find command, and worked
from there.
anyone else have any similar scripts like this ? i was thinking of having this run once a day or something, unpacking
my download dir where mostly movies or series land.
here is what i have so far, it will work from the path you give as argument, and scans all dirs for matching rar files and unpacks, but i cant delete in same loop if unrar breaks or isnt completely unpacked.
#!/ffp/bin/sh
if [ $# -ne 1 ]
then
echo "U forgot to enter directory where i should work!"
exit
fi
for f in `find $1 -path *.r01 -or -path *.part01.rar -or -path *.part1.rar -or -path *.part001.rar | sed -e 's/ /[SPACE]/g'`
do
f=`echo $f | sed -e 's/\[SPACE\]/ /g'`
echo "Unpacking : " $f " to " `dirname "$f"`
unrar e -o- -inul "$f" `dirname "$f"`
done
Offline
nevermind, after hours of instant googling i found enough examples
if anyone wants to use or improve something feel free to repost it here
now i need to set a fixed path and make it run every midnight or so from the dns nas
#!/ffp/bin/sh
if [ $# -ne 1 ]
then
echo "U forgot to enter directory where i should work!"
exit
fi
for f in `find $1 -path *.r01 -or -path *.part01.rar -or -path *.part1.rar -or -path *.part01.rar -or -path *.part001.rar | sed -e 's/ /[SPACE]/g'`
do
f=`echo $f | sed -e 's/\[SPACE\]/ /g'`
echo "Unpacking : " $f " to " `dirname "$f"`
unrar e -o- -inul "$f" `dirname "$f"`
err=$?
if [ $err = 0 ]
then
echo "Unpack completed, deleting rar files in " `dirname "$f"`
rm `dirname "$f"`/*.sfv
rm `dirname "$f"`/*.nfo
rm `dirname "$f"`/*.r??
rm -r `dirname $f`/Sample/
else
echo "[ERROR] Unrar failed on $f"
fi
if [ $err = 255 ]
then
echo "[ERROR] User stopped the process (exit code 255)"
echo "[ERROR] User stopped the process (exit code 255)" > `dirname "$f"`/error.txt
fi
if [ $err = 9 ]
then
echo "[ERROR] Create file error (exit code 9)"
echo "[ERROR] Create file error (exit code 9)" > `dirname "$f"`/error.txt
fi
if [ $err = 8 ]
then
echo "[ERROR] Not enough memory for operation (exit code 8)"
echo "[ERROR] Not enough memory for operation (exit code 8)" > `dirname "$f"`/error.txt
fi
if [ $err = 7 ]
then
echo "[ERROR] Command line option error (exit code 7)"
echo "[ERROR] Command line option error (exit code 7)" > `dirname "$f"`/error.txt
fi
if [ $err = 6 ]
then
echo "[ERROR] Open file error (exit code 6)"
echo "[ERROR] Open file error (exit code 6)" > `dirname "$f"`/error.txt
fi
if [ $err = 5 ]
then
echo "[ERROR] Write to disk error (exit code 5)"
echo "[ERROR] Write to disk error (exit code 5)" > `dirname "$f"`/error.txt
fi
if [ $err = 4 ]
then
echo "[ERROR] Attempt to modify an archive previously locked by the 'k' command (exit code 4)"
echo "[ERROR] Attempt to modify an archive previously locked by the 'k' command (exit code 4)" > `dirname "$f"`/error.txt
fi
if [ $err = 3 ]
then
echo "[ERROR] A CRC error occurred when unpacking (exit code 3)"
echo "[ERROR] A CRC error occurred when unpacking (exit code 3)" > `dirname "$f"`/error.txt
fi
if [ $err = 2 ]
then
echo "[ERROR] A fatal error occurred (exit code 2)"
echo "[ERROR] A fatal error occurred (exit code 2)" > `dirname "$f"`/error.txt
fi
if [ $err = 1 ]
then
echo "[ERROR] Non fatal error(s) occurred (exit code 1)"
echo "[ERROR] Non fatal error(s) occurred (exit code 1)" > `dirname "$f"`/error.txt
fi
if [ $err = 0 ]
then
echo "[OK] Successful operation (exit code 0)"
fi
done
Offline
I run something similar in cron every night. It doesn't go as far as checking CRCs, but it basically just scans for rar files (if transmission has no active downloads) and unrars them to the directory where they were found.
See unpacker.sh here and here.
Note: There is a regex bug with this script in that it will fail if there are spaces in the rar filename. I haven't had the patience to fix it yet.
I like your little "sed -e 's/ /[SPACE]/g'`" hackery tho. That might be a simple solution to my problem!
Offline
found an fault with script, it deletes all rarfiles after unpacking the first found so if theres several different sets of rar volumes its gone
tried a work around, it now works on dirs and filenames with spaces in, but im using a shitty way of deleting rar files after successful unpacking,
i cant make rm work with variables when the variable holds dirname/filename with spaces, but it works with echo, so it echo the rm line
to a sh script and executes it, then deletes the script before moving to next archive, if anyone can help me with a better way, please do
but its working, gonna put it in action on my download dir to run every 6 hrs or so.
here it is so far :
#!/ffp/bin/sh
if [ $# -ne 1 ]
then
echo "U forgot to enter directory where i should work!"
exit
fi
#look for rar archives and escape the paths found, spaces replaced with [space]
for f in `find $1 -path *.r01 -or -path *.part1.rar -or -path *.part01.rar -or -path *.part001.rar | sed -e 's/ /[SPACE]/g'`
do
#replace [space] with orginal spaces
f=`echo $f | sed -e 's/\[SPACE\]/ /g'`
echo "Unpacking : " $f " to " `dirname "$f"`
#unrar the archive to directory where its found
unrar e -o+ -inul "$f" `dirname "$f"`
err=$?
#check unrar return code if unpacking archive was success
# 0 = success
if [ $err = 0 ]
then
echo "Unpack completed, deleting rar files in " `dirname "$f"`
find `dirname "$f"` -type f 2>/dev/null|grep "$f" | sed 's|.*\/\([^\.]*\)\(\..*\)$|\1|g' |while read file #gets basename with sed
do
fuck="'"`dirname "$f"`"/"$file"'*.r??" #well funny variable naming
echo "#!/ffp/bin/sh" >>test.txt #test.txt is the script for deleting current archive unpacked
echo "rm $fuck" >>test.txt
sh test.txt
rm test.txt
#check for any sample/ directorys
find `dirname "$f"` -type d -iname sample* |while read dir
do
echo $dir
rm -r $dir >/dev/null
done
done
else
#jump here if any error with unpacking archive
echo "[ERROR] Unrar failed on $f"
fi
#return codes, write the return code in a text file named error.txt
if [ $err = 255 ]
then
echo "[ERROR] User stopped the process (exit code 255)"
echo "[ERROR] User stopped the process (exit code 255)" > `dirname "$f"`/error.txt
fi
if [ $err = 9 ]
then
echo "[ERROR] Create file error (exit code 9)"
echo "[ERROR] Create file error (exit code 9)" > `dirname "$f"`/error.txt
fi
if [ $err = 8 ]
then
echo "[ERROR] Not enough memory for operation (exit code 8)"
echo "[ERROR] Not enough memory for operation (exit code 8)" > `dirname "$f"`/error.txt
fi
if [ $err = 7 ]
then
echo "[ERROR] Command line option error (exit code 7)"
echo "[ERROR] Command line option error (exit code 7)" > `dirname "$f"`/error.txt
fi
if [ $err = 6 ]
then
echo "[ERROR] Open file error (exit code 6)"
echo "[ERROR] Open file error (exit code 6)" > `dirname "$f"`/error.txt
fi
if [ $err = 5 ]
then
echo "[ERROR] Write to disk error (exit code 5)"
echo "[ERROR] Write to disk error (exit code 5)" > `dirname "$f"`/error.txt
fi
if [ $err = 4 ]
then
echo "[ERROR] Attempt to modify an archive previously locked by the 'k' command (exit code 4)"
echo "[ERROR] Attempt to modify an archive previously locked by the 'k' command (exit code 4)" > `dirname "$f"`/error.txt
fi
if [ $err = 3 ]
then
echo "[ERROR] A CRC error occurred when unpacking (exit code 3)"
echo "[ERROR] A CRC error occurred when unpacking (exit code 3)" > `dirname "$f"`/error.txt
fi
if [ $err = 2 ]
then
echo "[ERROR] A fatal error occurred (exit code 2)"
echo "[ERROR] A fatal error occurred (exit code 2)" > `dirname "$f"`/error.txt
fi
if [ $err = 1 ]
then
echo "[ERROR] Non fatal error(s) occurred (exit code 1)"
echo "[ERROR] Non fatal error(s) occurred (exit code 1)" > `dirname "$f"`/error.txt
fi
if [ $err = 0 ]
then
echo "[OK] Successful operation (exit code 0)"
fi
done
Offline