Skip to main content

Thread: script to check parities and extract files


hello all,

have made little shell script check parities , extract (only legally obtained!) downloads have arrived on server / nas. runs every 15 minutes using cron.

because might useful others, , because shell scripting relatively new me such may contain potential flaws (though seems work fine), thought i'd post here. comments welcome!


code:
#/bin/sh  check_parity() { 	filename=${1%\.*}         #we assume when download finished doesn't increase anymore 	count=`ls | wc -l` 	sleep 600 	recount=`ls | wc -l` 	if test $count  != $recount; 		then return 		fi 	par2 r $1 	if test $? != 0; 		then                         #if repairing didn't succeed, files moved newly made folder, norepair 			mkdir norepair 			mv "$filename".* norepair/ 		else                         #otherwise attempt extract 			mkdir finished 			mv "$filename".* finished/ 			cd finished 			rm *.par2 *.nfo *.sfv 			unrar e "$filename".rar 			if test $? = 0;                                 #only if extraction succeeded well, delete archives. 				then rm "$filename".rar "$filename".r*	 				fi 			cd ..	 		fi 	return }   #first check wether system in standby state, don't want wake up. standby=`hdparm -c /dev/sdb1 | grep active | grep -v grep | wc -l` echo "harddisk status equals $standby" if test $standby = 0; 	then exit 1               	fi      #if previous script still running, don't start second instance processes=`ps | grep check_dl_parity.sh | grep -v grep | wc -l` echo "$processes instances running" if test $processes -gt 3; #for reasons don't understand, minimum here 3 	then exit 1 	fi  cd /home/server/downloads  # whether parity files present in downloads folder in /home/server/downloads/*; 	cd "$i" 	set *.par2 	echo "$i" 	if test "$1" = "*.par2"; 		then echo "no parities found" 		else check_parity $1 ; #start parity function 		fi 	cd .. done



Forum The Ubuntu Forum Community Ubuntu Official Flavours Support Multimedia Software [all variants] script to check parities and extract files


Ubuntu

Comments

Popular posts from this blog

How to set the order of FAQs instead of alphabetical

Thread: Get UK Keyboard working

how do I change the e-mail address for my merchant account