Good for folders which contain many zip files, and rar files. If you want to use them have at it. My advice: read up the comments and test them first on folders you have zips & rars. Some are a combo utility, like rtunzip scripts will unzip and then follow with unrars (because lots of zips contains rars). fix-permission script thats mentioned is personal forgetaboutit.

This is a continuation from this: unrar123

Its probably best you copy out all of these out to notepad++ or sublime and analyze the code. Each script is separated between the percent-sign line separators. Date is at the top so you know how late these scripts are.

I used unrar2 the most, its the one that extracts to an _extracted / _ex-archivename folder in the same folder as where the rar is at. So I decided to do just that with the unzip scripts. So I didnt make a synomous unzip script for unrar1 & unrar3. So I dont have unzip scripts that extract to the same folder (like my unrar1 script) and I dont have unzip scripts that extract to a different directory tree (like my unrar3 script). Instead the unrar3 scripts

NOTE TO SELF: to get latest scripts run this ~/scripts/print-unrars-unzips.sh

Daily updated: http://www.infotinks.com/scripts/unrar123-unzip2-scripts.txt

Below is syntax highlighted and updated when I feel like it (for latest go to above link)

DATE: Tue Apr 28 02:01:15 PDT 2015 - 1430211675
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
* /usr/local/sbin/unrar1samedir.sh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#!/bin/bash
# WHAT THIS DOES:
# The below script will extract each rar file into its current directory (the rars will make whatever subdirectories they need to make - which ever ones they contain of course).
# WHAT TO DO:
# 1. fill out SOURCE variable (thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation) or run as script
# - if running as script it will start looking at files from the current folder, not where the script is
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=`pwd`
echo "$0 STARTING RECURSIVE UNRAR TO SAME DIRS AS THE RAR FILES ARE AT, STARTING AT $SOURCE"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
cd "${SOURCE}"
OLDIFS=$IFS
IFS=$'\n'
COUNT=0; COUNT1=0; COUNT2=0; COUNT3=0; COUNT4=0;
echo "#### --[$0][$$][`date +%D-%T`/`date +%s`]-- ####" > /var/log/unrar123.brief
for i in `find -type f | grep \.rar$`; do
	COUNT0=$((COUNT0+1));
	echo "### --------[`date +%D-%T`][`date +%s`]--------";
	FILEFULLPATH=`readlink -f "${i}"`;
	FULLDIR=`dirname "${FILEFULLPATH}"`;
	DSTDIR="${FULLDIR}";
	echo "### ${COUNT0}. EXTRACTING ${i} TO ${DSTDIR}:"
	echo "### unrar x $OVERWRITE ${i} ${DSTDIR}"
	EXTRACTED1="${i}.extracted"
	if [ -f "${EXTRACTED1}" ]; then
	   TMPW="PREVIOUSLY EXTRACTED"
	   COUNT1=$((COUNT1+1));
	   echo "[`date`] [`date +%s`] Attempted $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   echo "    File has already been extracted, to try again: 'rm $EXTRACTED1'"
	   cat "${EXTRACTED1}" | grep . | awk '{print "*       " $0;}'
	   echo "    *** $COUNT1 non-extractable rar files ($COUNT0 total rars scanned)"
	else
	   COUNT2=$((COUNT2+1));
	   echo "    *** $COUNT2 extractable rar files ($COUNT0 total rars scanned)"
	   ### unrar x $OVERWRITE "${i}" "${FULLDIR}" |& grep . |& awk '{print "*    " $0;}' && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   ### STATUS="FAIL"
	   STATUSFILE=/tmp/unrar1status-`date +%s`-`echo $$`
	   echo "FAIL" > $STATUSFILE
	   (unrar x $OVERWRITE "${i}" "${DSTDIR}" && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}" && echo "SUCCESS" > $STATUSFILE) |& grep . |& awk '{print "*    " $0;}'
	   echo "$0|`date`/`date +%s`|`cat $STATUSFILE`|$SOURCE|$i" >> /var/log/unrar123.log
	   if grep -q "^SUCCESS$" "$STATUSFILE"; then
	        TMPW="EXTRACTION SUCCESSFUL"
			COUNT3=$((COUNT3+1));
			echo "   *** Extracted Succesfully - along with $COUNT3 out of $COUNT2 extractable rars"
	   else
	        TMPW="EXTRACTION FAILED"
			COUNT4=$((COUNT4+1));
			echo "   *** Failed to Extract - along with $COUNT4 out of $COUNT2 extractable rars"
	   fi
	   rm $STATUSFILE
	fi
	echo "   *** TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" | tee -a /var/log/unrar123.log
	echo "* ${FILEFULLPATH} : ${TMPW}" >> /var/log/unrar123.brief
done;
echo "* TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" >> /var/log/unrar123.brief
cat /var/log/unrar123.brief >> /var/log/unrar123.allbrief
IFS=$OLDIFS)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
* /usr/local/sbin/unrar2extracted.sh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#!/bin/bash
# WHAT THIS DOES:
# The below script will extract each rar file into its current directory within a special _extracted folder in each directory for extra organization (the rars will make whatever subdirectories they need to make - which ever ones they contain of course).
# WHAT TO DO:
# 1. fill out SOURCE variable (thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation). Or run it as script.
# - if run as script, it will look for files in current shell folder, not where the script resides (unless thats where your current folder is)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE="`pwd`"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
echo "$0 STARTING RECURSIVE UNRAR & CREATING _extracted FOLDERS IN SAME FOLDER AS RAR FILES, STARTING HERE: $SOURCE"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
cd "${SOURCE}"
OLDIFS=$IFS
IFS=$'\n'
COUNT=0; COUNT1=0; COUNT2=0; COUNT3=0; COUNT4=0;
echo "#### --[$0][$$][`date +%D-%T`/`date +%s`]-- ####" > /var/log/unrar123.brief
for i in `find -type f | grep \.rar$`; do
    COUNT0=$((COUNT0+1));
	echo "### --------[`date +%D-%T`][`date +%s`]--------";
	FILEFULLPATH=`readlink -f "${i}"`;
	FULLDIR=`dirname "${FILEFULLPATH}"`;
	## ORIGINAL DST DIR:
	DSTDIR="${FULLDIR}/_extracted"
	## DSTDIR  is where we are extracting, it has the suffix. Orignally it was just _extracted, but that was probablematic for files like part01.rar and part02.rar (in case there are many rars in the same folder)
	## DSTDIR="${FULLDIR}/_extracted-`date +%s`-`echo $$`"
	## another variation to DSTDIR that has filename - start ###
	### FNAMEPART=`basename "${FILEFULLPATH}"`
	### FSUFFIX=`echo "${FNAMEPART%.*}" | sed -e 's/[^A-Za-z0-9_-]/_/g'`
	### DSTDIR="${FULLDIR}/_ex-`date +%s`-${FSUFFIX}"
	#### DSTDIRFAIL="${DSTDIR}-FAIL-DELETE"
	## another variation to DSTDIR that has filename - end ###
	mkdir -p "${DSTDIR}" 2> /dev/null
	echo "### ${COUNT0}. EXTRACTING ${i} TO ${DSTDIR}:"
	echo "### unrar x $OVERWRITE ${i} ${DSTDIR}"
	EXTRACTED1="${i}.extracted"
	if [ -f "${EXTRACTED1}" ]; then
	   TMPW="PREVIOUSLY EXTRACTED"
	   COUNT1=$((COUNT1+1));
	   echo "[`date`] [`date +%s`] Attempted $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   echo "    File has already been extracted, to try again: 'rm $EXTRACTED1'"
	   cat "${EXTRACTED1}" | grep . | awk '{print "*       " $0;}'
	   echo "    *** $COUNT1 non-extractable rar files ($COUNT0 total rars scanned)"
	else
	   COUNT2=$((COUNT2+1));
	   echo "    *** $COUNT2 extractable rar files ($COUNT0 total rars scanned)"
	   ###unrar x $OVERWRITE "${i}" "${FULLDIR}/_extracted" |& grep . |& awk '{print "*    " $0;}' && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   STATUSFILE=/tmp/unrar2status-`date +%s`-`echo $$`
	   echo "FAIL" > $STATUSFILE
	   (unrar x $OVERWRITE "${i}" "${DSTDIR}" && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}" && echo "SUCCESS" > $STATUSFILE)  |& grep . |& awk '{print "*    " $0;}'
	   echo "$0|`date`/`date +%s`|`cat $STATUSFILE`|$SOURCE|$i" >> /var/log/unrar123.log
	   ### added this to delete rars - start ###
	   if grep -q "^SUCCESS$" "$STATUSFILE"; then
	   	   TMPW="EXTRACTION SUCCESSFUL"
	       COUNT3=$((COUNT3+1));
		   echo "   *** Extracted Succesfully - along with $COUNT3 out of $COUNT2 extractable rars"
	   else
	       TMPW="EXTRACTION FAILED"
	       COUNT4=$((COUNT4+1));
		   echo "   *** Failed to Extract - along with $COUNT4 out of $COUNT2 extractable rars"
		   #### echo "+ NOT SUCCESSFUL UNRAR -> Renaming Failed Destination"
		   #### echo "+ Renaming Failed Destination to: ${DSTDIRFAIL}"
		   #### mv -f "${DSTDIR}" "${DSTDIRFAIL}"
		   echo "+ NOT SUCCESSFUL UNRAR -> Removing Failed Destination"
		   echo "+ Deleting Failed Destination: ${DSTDIR}"
		   rm -rf "${DSTDIR}"
	   fi
	   ### added this to delete rars - end ###
	   # delete the status file, so as to not fill up the /tmp folder
	   rm $STATUSFILE
	fi
	echo "   *** TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" | tee -a /var/log/unrar123.log
	echo "* ${FILEFULLPATH} : ${TMPW}" >> /var/log/unrar123.brief
done;
echo "* TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" >> /var/log/unrar123.brief
cat /var/log/unrar123.brief >> /var/log/unrar123.allbrief
IFS=$OLDIFS)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
* /usr/local/sbin/unrar3todir.sh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#!/bin/bash
# usage: $0 <diff directory to extract to>
# WHAT THIS DOES:
# this will take a folder structure with lots of rars, and copy it to another folder set, but extract all the rars nicely
# WHAT TO DO:
# 1. fill out SOURCE & DESTINATION variable
# or 1. Run as script "usage: unrar3todir.sh <directory>" - not it will extract every rar file recursively from current folder (not where script is, but where you are in the shell) to the dest folder specified
# note about the source: thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation
# note about the destination: this will only copy out the folder structure as is for rar files, then it will also make the correct folder structure that the rar files contained within them. When typing the destination folder, it doesnt matter if it ends in a / or doesnt (same goes for source)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# make sure that the destination folder is not in the source folder
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=`pwd`
DESTINATION="$1"
if [ -z $DESTINATION ]; then echo -e "UNRAR RECURSIVELY TO DIFFERENT DIRS\nusage: $0 <directory to extract to>"; exit 1; fi
echo "$0 IS STARTING RECURSIVE UNRAR OF $SOURCE TO $DESTINATION"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
OLDIFS=$IFS
IFS=$'\n'
cd "${SOURCE}"
mkdir -p "${DESTINATION}" 2> /dev/null
DESTINATION=`readlink -f "${DESTINATION}"`
COUNT=0; COUNT1=0; COUNT2=0; COUNT3=0; COUNT4=0;
echo "#### --[$0][$$][`date +%D-%T`/`date +%s`]-- ####" > /var/log/unrar123.brief
for i in `find -type f | grep \.rar$`; do
	COUNT0=$((COUNT0+1));
	echo "### --------[`date +%D-%T`][`date +%s`]--------";
	FILEFULLPATH=`readlink -f "${i}"`;
	RELATIVEDIR=`dirname "${i}"`;
	NEWRDIR="${RELATIVEDIR#.}"
	DSTDIR="${DESTINATION}${NEWRDIR}"
	echo "### ${COUNT0}. EXTRACTING ${i} TO ${NEWRDIR}:"
	#mkdir -p "${DESTINATION}${NEWRDIR}" 2> /dev/null
	echo "### unrar x ${FILEFULLPATH} ${DSTDIR}";
	EXTRACTED1="${i}.extracted"
	if [ -f "${EXTRACTED1}" ]; then
	   TMPW="PREVIOUSLY EXTRACTED"
	   COUNT1=$((COUNT1+1));
	   echo "[`date`] [`date +%s`] Attempted $0 on SRC: $SOURCE, DST: $DESTINATION" >> "${EXTRACTED1}"
	   echo "    File has already been extracted, to try again: 'rm $EXTRACTED1'"
	   cat "${EXTRACTED1}" | grep . | awk '{print "*       " $0;}'
	   echo "    *** $COUNT1 non-extractable rar files ($COUNT0 total rars scanned)"
	else
	   COUNT2=$((COUNT2+1));
	   echo "    *** $COUNT2 extractable rar files ($COUNT0 total rars scanned)"
	   mkdir -p "${DSTDIR}" 2> /dev/null
	   ### unrar x $OVERWRITE "${FILEFULLPATH}" "${DESTINATION}${NEWRDIR}" |& grep . |& awk '{print "*    " $0;}' && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE, DST: $DESTINATION" >> "${EXTRACTED1}"
	   ### STATUS="FAIL"
	   STATUSFILE=/tmp/unrar3status-`date +%s`-`echo $$`
	   echo "FAIL" > $STATUSFILE
	   (unrar x $OVERWRITE "${FILEFULLPATH}" "${DSTDIR}" && (echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE, DST: $DESTINATION"; echo "SUCCESS" > $STATUSFILE;) >> "${EXTRACTED1}" || echo "[`date`][`date +%s`] Failed $0 on SRC: $SOURCE, DST: $DESTINATION - $FILEFULLPATH" >> ${DSTDIR}/failed-unrar3.txt) |& grep . |& awk '{print "*    " $0;}'
	   echo "$0|`date`/`date +%s`|`cat $STATUSFILE`|$SOURCE|$i --> $DESTINATION" >> /var/log/unrar123.log
	   if grep -q "^SUCCESS$" "$STATUSFILE"; then
	      TMPW="EXTRACTION SUCCESSFUL"
		  COUNT3=$((COUNT3+1));
		  echo "   *** Extracted Succesfully - along with $COUNT3 out of $COUNT2 extractable rars"
	   else
	      TMPW="EXTRACTION FAILED"
		  COUNT4=$((COUNT4+1));
		  echo "   *** Failed to Extract - along with $COUNT4 out of $COUNT2 extractable rars"
	   fi
	   rm $STATUSFILE
	fi
	echo "   *** TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" | tee -a /var/log/unrar123.log
	echo "* ${FILEFULLPATH} : ${TMPW}" >> /var/log/unrar123.brief
done;
echo "* TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" >> /var/log/unrar123.brief
cat /var/log/unrar123.brief >> /var/log/unrar123.allbrief
IFS=$OLDIFS)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
* /usr/local/bin/rtunzip-any-currentfolder.sh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#!/bin/bash
# this unzips everything into _ex, where zips are, then it unrars
MAIN_FOLDER=`pwd`
START_FOLDER=`readlink -f "$MAIN_FOLDER"`
(
# THIS PART OF THE SCRIPT IN THE () IS CALLED unzip123.zip (its alike to unrar2) where unrar2 unzips everything to an _Extracted folder in the same folder as where the rar file is, this will extract it to _ex
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo
# go to folder where the zip->rar->stuff structure is (my current folder)
cd "$START_FOLDER"
# save ifs
OIFS=$IFS
IFS=$'\n'
FOLDER_LIST=`(for i in $(find -type f | grep "\.zip$"); do dirname "$i"; done;) | sort | uniq`
# going thru every folder
for CUR_FOLDER in $FOLDER_LIST; do
	echo "########################################################### [`date` - `date +%s` s]"
	echo "* Checking out ZIPS in $CUR_FOLDER "
	# get into dir
	cd "$CUR_FOLDER"
	# if the zips already been extracted lets skip this
	if [ -f .zip-extracted ]; then
		echo "* ZIPS ALREADY EXTRACTED: loggin attempt to it"
		cat .zip-extracted
		echo "[`date` - `date +%s` s] zip already extracted (just stepped over it) " | tee -a .zip-extracted | awk '{print "   " $0}'		
	else
		# mkdir for zips that contain more zips
		mkdir _ex
		# count of all good zips
		COUNT_OF_ZIPS=`find . -maxdepth 1 -type f | grep "\.zip$" | wc -l`
		GOOD_ZIPS=0
		for i in *zip; do 
			unzip -o $i -d _ex | awk '{print "   " $0}'
			if [ $? -eq 0 ]; then
				# if extracted well then count up
				GOOD_ZIPS=$((GOOD_ZIPS+1))
			fi
		done;
		# hopefully extracted as many as there are zip files
		if [ ${COUNT_OF_ZIPS} -eq ${GOOD_ZIPS} ]; then
			echo "[`date` - `date +%s` s] Zip Success - Extracted $GOOD_ZIPS zips in $CUR_FOLDER folder " | tee -a .zip-extracted # make this file so in future if we go over this folder we dont need to extract the zips again
		fi
	fi
	echo;
	# get back to normal location, so loop can work again
	cd "$START_FOLDER"
done
IFS=$OIFS
echo "* check /var/log/unrar123 files to see how the next and final step of unrar and fixperming went"
echo 
) | tee -a /var/log/unzip123.log
echo "=========================="
echo "Running RTUNRAR2NFIX Twice"
echo "=========================="
#run unrar with fixperms twice (logs to /var/log/unrar123) - fix perms runs from within UNRAR2NFIX (which runs on current folder)
/root/scripts/UNRAR2NFIX.sh
/root/scripts/UNRAR2NFIX.sh
# remind of log
echo "========================"
echo "`basename $0` FINAL WORDS"
echo "========================"
echo "* Dont forget to check out /var/log/unzip123.log"
cp /var/log/unzip123.log /data/Main/Downloads/unzip123.txt
# so windows can see
unix2dos /data/Main/Downloads/unzip123.txt


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
* /usr/local/bin/rtunzip-rtfolder.sh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#!/bin/bash
# this goes thru RT download folder and extracts all zips to _ex, and proceeds with unrar2 everything because zips usually hold stuff like that
# unrar2 is ran thru RTUNRAR script which also fixes permissions
# just run the script and your good to go.
(
# THIS PART OF THE SCRIPT IN THE () IS CALLED unzip123.zip (its alike to unrar2) where unrar2 unzips everything to an _Extracted folder in the same folder as where the rar file is, this will extract it to _ex
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo
# go to folder where the zip->rar->stuff structure is (my /RT folder)
cd /RT
# save ifs
OIFS=$IFS
IFS=$'\n'
FOLDER_LIST=`(for i in $(find -type f | grep "\.zip$"); do dirname "$i"; done;) | sort | uniq`
# going thru every folder
for CUR_FOLDER in $FOLDER_LIST; do
	echo "########################################################### [`date` - `date +%s` s]"
	echo "* Checking out ZIPS in $CUR_FOLDER "
	# get into dir
	cd "$CUR_FOLDER"
	# if the zips already been extracted lets skip this
	if [ -f .zip-extracted ]; then
		echo "* ZIPS ALREADY EXTRACTED: loggin attempt to it"
		cat .zip-extracted
		echo "[`date` - `date +%s` s] zip already extracted (just stepped over it) " | tee -a .zip-extracted | awk '{print "   " $0}'		
	else
		# mkdir for zips that contain more zips
		mkdir _ex
		# count of all good zips
		COUNT_OF_ZIPS=`find . -maxdepth 1 -type f | grep "\.zip$" | wc -l`
		GOOD_ZIPS=0
		for i in *zip; do 
			unzip -o $i -d _ex | awk '{print "   " $0}'
			if [ $? -eq 0 ]; then
				# if extracted well then count up
				GOOD_ZIPS=$((GOOD_ZIPS+1))
			fi
		done;
		# hopefully extracted as many as there are zip files
		if [ ${COUNT_OF_ZIPS} -eq ${GOOD_ZIPS} ]; then
			echo "[`date` - `date +%s` s] Zip Success - Extracted $GOOD_ZIPS zips in $CUR_FOLDER folder " | tee -a .zip-extracted # make this file so in future if we go over this folder we dont need to extract the zips again
		fi
	fi
	echo;
	# get back to normal location, so loop can work again
	cd /RT
done
IFS=$OIFS
echo "* check /var/log/unrar123 files to see how the next and final step of unrar and fixperming went"
echo 
) | tee -a /var/log/unzip123.log
echo "=========================="
echo "Running RTUNRAR2NFIX Twice"
echo "=========================="
#run unrar with fixperms twice (logs to /var/log/unrar123)
RTUNRAR2NFIX.sh
RTUNRAR2NFIX.sh
# remind of log
echo "========================"
echo "`basename $0` FINAL WORDS"
echo "========================"
echo "* Dont forget to check out /var/log/unzip123.log"
cp /var/log/unzip123.log /data/Main/Downloads/unzip123.txt
# so windows can see
unix2dos /data/Main/Downloads/unzip123.txt


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
* /usr/local/bin/unrar1samedir-delete-rars.sh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#!/bin/bash
# WHAT THIS DOES:
# The below script will extract each rar file into its current directory (the rars will make whatever subdirectories they need to make - which ever ones they contain of course).
# this will also delete the rar files after successful extraction (including the split/volume files)
# WHAT TO DO:
# 1. fill out SOURCE variable (thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation) or run as script
# - if running as script it will start looking at files from the current folder, not where the script is
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=`pwd`
echo "$0 STARTING RECURSIVE UNRAR TO SAME DIRS AS THE RAR FILES ARE AT, STARTING AT $SOURCE"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
cd "${SOURCE}"
OLDIFS=$IFS
IFS=$'\n'
COUNT=0; COUNT1=0; COUNT2=0; COUNT3=0; COUNT4=0;
echo "#### --[$0][$$][`date +%D-%T`/`date +%s`]-- ####" > /var/log/unrar123.brief
for i in `find -type f | grep \.rar$`; do
	COUNT0=$((COUNT0+1));
	echo "### --------[`date +%D-%T`][`date +%s`]--------";
	FILEFULLPATH=`readlink -f "${i}"`;
	FULLDIR=`dirname "${FILEFULLPATH}"`; ## Since extracting to the same directory DSTDIR is the same as FULLDIR
	DSTDIR="${FULLDIR}";
	echo "### ${COUNT0}. EXTRACTING ${i} TO ${DSTDIR}:"
	echo "### unrar x $OVERWRITE ${i} ${DSTDIR}"
	EXTRACTED1="${i}.extracted"
	if [ -f "${EXTRACTED1}" ]; then
	   TMPW="PREVIOUSLY EXTRACTED"
	   COUNT1=$((COUNT1+1));
	   echo "[`date`] [`date +%s`] Attempted $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   echo "    File has already been extracted, to try again: 'rm $EXTRACTED1'"
	   cat "${EXTRACTED1}" | grep . | awk '{print "*       " $0;}'
	   echo "    *** $COUNT1 non-extractable rar files ($COUNT0 total rars scanned)"
	else
	   TMPW="EXTRACTION SUCCESSFUL"
	   COUNT2=$((COUNT2+1));
	   echo "    *** $COUNT2 extractable rar files ($COUNT0 total rars scanned)"
	   ### unrar x $OVERWRITE "${i}" "${FULLDIR}" |& grep . |& awk '{print "*    " $0;}' && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   ### STATUS="FAIL"
	   STATUSFILE=/tmp/unrar1status-`date +%s`-`echo $$`
	   echo "FAIL" > $STATUSFILE
	   (unrar x $OVERWRITE "${i}" "${DSTDIR}" && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}" && echo "SUCCESS" > $STATUSFILE) |& grep . |& awk '{print "*    " $0;}'
	   echo "$0|`date`/`date +%s`|`cat $STATUSFILE`|$SOURCE|$i" >> /var/log/unrar123.log
	   ### added this to delete rars - start ###
	   if grep -q "^SUCCESS$" "$STATUSFILE"; then
	       TMPW="EXTRACTION FAILED"
	       COUNT3=$((COUNT3+1));
		   echo "   *** Extracted Succesfully - along with $COUNT3 out of $COUNT2 extractable rars"
		   VV=0
		   for j in `unrar la -v "${FILEFULLPATH}"  | awk '/^Archive:/{$1="";print $0}' | sed 's/^[ \t]*//;s/[ \t]*$//'`; do
			   VV=$((VV+1))
			   DELETEVOL="$j"
			   ## DELETEVOLFULLPATH="$FULLDIR/$j"
			   (echo -n "+ ${VV} SUCCESSFUL UNRAR -> Deleting rar volume: ${DELETEVOL}: "
			   rm -f "${DELETEVOL}" && echo "deleted!" || echo "delete failed!") |  tee -a "${EXTRACTED1}"
		   done
	   else
	       COUNT4=$((COUNT4+1));
		   echo "   *** Failed to Extract - along with $COUNT4 out of $COUNT2 extractable rars"
		   echo "+ NOT SUCCESSFUL UNRAR -> Not deleting rar volume[s]"
	   fi
	   ### added this to delete rars - end ###
	   # delete the status file, so as to not fill up the /tmp folder
	   rm $STATUSFILE
	fi
	echo "   *** TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" | tee -a /var/log/unrar123.log
    echo "* ${FILEFULLPATH} : ${TMPW}" >> /var/log/unrar123.brief
done;
echo "* TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" >> /var/log/unrar123.brief
cat /var/log/unrar123.brief >> /var/log/unrar123.allbrief
IFS=$OLDIFS)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
* /usr/local/bin/unrar2extracted-delete-rars.sh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#!/bin/bash
# WHAT THIS DOES:
# The below script will extract each rar file into its current directory within a special _extracted folder in each directory for extra organization (the rars will make whatever subdirectories they need to make - which ever ones they contain of course).
# this will also delete the rar files after successful extraction (including the split/volume files)
# the extracted path is actually not _extracted but its "_ex-datetime-filename"
# WHAT TO DO:
# 1. fill out SOURCE variable (thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation). Or run it as script.
# - if run as script, it will look for files in current shell folder, not where the script resides (unless thats where your current folder is)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE="`pwd`"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
echo "$0 STARTING RECURSIVE UNRAR & CREATING _extracted FOLDERS IN SAME FOLDER AS RAR FILES, STARTING HERE: $SOURCE"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
cd "${SOURCE}"
OLDIFS=$IFS
IFS=$'\n'
COUNT=0; COUNT1=0; COUNT2=0; COUNT3=0; COUNT4=0;
echo "#### --[$0][$$][`date +%D-%T`/`date +%s`]-- ####" > /var/log/unrar123.brief
for i in `find -type f | grep \.rar$`; do
	COUNT0=$((COUNT0+1));
	echo "### --------[`date +%D-%T`][`date +%s`]--------";
	FILEFULLPATH=`readlink -f "${i}"`;
	FULLDIR=`dirname "${FILEFULLPATH}"`;
	## ORIGINAL DST DIR:
	## DSTDIR="${FULLDIR}/_extracted"
	## DSTDIR  is where we are extracting, it has the suffix. Orignally it was just _extracted, but that was probablematic for files like part01.rar and part02.rar (in case there are many rars in the same folder)
	## DSTDIR="${FULLDIR}/_extracted-`date +%s`-`echo $$`"
	## another variation to DSTDIR that has filename - start ###
	FNAMEPART=`basename "${FILEFULLPATH}"`
	FSUFFIX=`echo "${FNAMEPART%.*}" | sed -e 's/[^A-Za-z0-9_-]/_/g'`
	DSTDIR="${FULLDIR}/_ex-`date +%s`-${FSUFFIX}"
	#### DSTDIRFAIL="${DSTDIR}-FAIL-DELETE"
	## another variation to DSTDIR that has filename - end ###
	mkdir -p "${DSTDIR}" 2> /dev/null
	echo "### ${COUNT0}. EXTRACTING ${i} TO ${DSTDIR}:"
	echo "### unrar x $OVERWRITE ${i} ${DSTDIR}"
	EXTRACTED1="${i}.extracted"
	if [ -f "${EXTRACTED1}" ]; then
	TMPW="PREVIOUSLY EXTRACTED"
	   COUNT1=$((COUNT1+1));
	   echo "[`date`] [`date +%s`] Attempted $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   echo "    File has already been extracted, to try again: 'rm $EXTRACTED1'"
	   cat "${EXTRACTED1}" | grep . | awk '{print "*       " $0;}'
	   echo "    *** $COUNT1 non-extractable rar files ($COUNT0 total rars scanned)"
	else
	   COUNT2=$((COUNT2+1));
	   echo "    *** $COUNT2 extractable rar files ($COUNT0 total rars scanned)"
	   ###unrar x $OVERWRITE "${i}" "${FULLDIR}/_extracted" |& grep . |& awk '{print "*    " $0;}' && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   STATUSFILE=/tmp/unrar2status-`date +%s`-`echo $$`
	   echo "FAIL" > $STATUSFILE
	   (unrar x $OVERWRITE "${i}" "${DSTDIR}" && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}" && echo "SUCCESS" > $STATUSFILE)  |& grep . |& awk '{print "*    " $0;}'
	   echo "$0|`date`/`date +%s`|`cat $STATUSFILE`|$SOURCE|$i" >> /var/log/unrar123.log
	   ### added this to delete rars - start ###
	   if grep -q "^SUCCESS$" "$STATUSFILE"; then
	   	   TMPW="EXTRACTION SUCCESSFUL"
	       COUNT3=$((COUNT3+1));
		   echo "   *** Extracted Succesfully - along with $COUNT3 out of $COUNT2 extractable rars"
		   VV=0
		   for j in `unrar la -v "${FILEFULLPATH}"  | awk '/^Archive:/{$1="";print $0}' | sed 's/^[ \t]*//;s/[ \t]*$//'`; do
			   VV=$((VV+1))
			   DELETEVOL="$j"
			   (echo -n "+ ${VV} SUCCESSFUL UNRAR -> Deleting rar volume: ${DELETEVOL}: "
			   rm -f "${DELETEVOL}" && echo "deleted!" || echo "delete failed!") |  tee -a "${EXTRACTED1}"
		   done
	   else
	       TMPW="EXTRACTION FAILED"
	       COUNT4=$((COUNT4+1));
		   echo "   *** Failed to Extract - along with $COUNT4 out of $COUNT2 extractable rars"
		   #### echo "+ NOT SUCCESSFUL UNRAR -> Renaming output folder & Not deleting rar volume[s]"
		   #### echo "+ Renaming Failed Destination to: ${DSTDIRFAIL}"
		   #### mv -f "${DSTDIR}" "${DSTDIRFAIL}"
		   echo "+ NOT SUCCESSFUL UNRAR -> Deleting output folder & Not deleting rar volume[s]"
		   echo "+ Removing Failed Destination: ${DSTDIR}"
		   rm -rf "${DSTDIR}"
	   fi
	   ### added this to delete rars - end ###
	   # delete the status file, so as to not fill up the /tmp folder
	   rm $STATUSFILE
	fi
	echo "   *** TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" | tee -a /var/log/unrar123.log
	echo "* ${FILEFULLPATH} : ${TMPW}" >> /var/log/unrar123.brief
done;
echo "* TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" >> /var/log/unrar123.brief
cat /var/log/unrar123.brief >> /var/log/unrar123.allbrief
IFS=$OLDIFS)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
* /usr/local/bin/unrar3todir-delete-rars.sh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#!/bin/bash
# usage: $0 <diff directory to extract to>
# WHAT THIS DOES:
# this will take a folder structure with lots of rars, and copy it to another folder set, but extract all the rars nicely
# this will also delete the rar files after successful extraction (including the split/volume files)
# WHAT TO DO:
# 1. fill out SOURCE & DESTINATION variable
# or 1. Run as script "usage: unrar3todir.sh <directory>" - not it will extract every rar file recursively from current folder (not where script is, but where you are in the shell) to the dest folder specified
# note about the source: thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation
# note about the destination: this will only copy out the folder structure as is for rar files, then it will also make the correct folder structure that the rar files contained within them. When typing the destination folder, it doesnt matter if it ends in a / or doesnt (same goes for source)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# make sure that the destination folder is not in the source folder
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=`pwd`
DESTINATION="$1"
if [ -z $DESTINATION ]; then echo -e "UNRAR RECURSIVELY TO DIFFERENT DIRS\nusage: $0 <directory to extract to>"; exit 1; fi
echo "$0 IS STARTING RECURSIVE UNRAR OF $SOURCE TO $DESTINATION"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
OLDIFS=$IFS
IFS=$'\n'
cd "${SOURCE}"
mkdir -p "${DESTINATION}" 2> /dev/null
DESTINATION=`readlink -f "${DESTINATION}"`
COUNT=0; COUNT1=0; COUNT2=0; COUNT3=0; COUNT4=0;
echo "#### --[$0][$$][`date +%D-%T`/`date +%s`]-- ####" > /var/log/unrar123.brief
for i in `find -type f | grep \.rar$`; do
	COUNT0=$((COUNT0+1));
	echo "### --------[`date +%D-%T`][`date +%s`]--------";
	FILEFULLPATH=`readlink -f "${i}"`;
	RELATIVEDIR=`dirname "${i}"`;
	NEWRDIR="${RELATIVEDIR#.}"
	DSTDIR="${DESTINATION}${NEWRDIR}"
	echo "### ${COUNT0}. EXTRACTING ${i} TO ${NEWRDIR}:"
	#mkdir -p "${DESTINATION}${NEWRDIR}" 2> /dev/null
	echo "### unrar x ${FILEFULLPATH} ${DSTDIR}";
	EXTRACTED1="${i}.extracted"
	if [ -f "${EXTRACTED1}" ]; then
	   TMPW="PREVIOUSLY EXTRACTED"
	   COUNT1=$((COUNT1+1));
	   echo "[`date`] [`date +%s`] Attempted $0 on SRC: $SOURCE, DST: $DESTINATION" >> "${EXTRACTED1}"
	   echo "    File has already been extracted, to try again: 'rm $EXTRACTED1'"
	   cat "${EXTRACTED1}" | grep . | awk '{print "*       " $0;}'
	   echo "    *** $COUNT1 non-extractable rar files ($COUNT0 total rars scanned)"
	else
	   COUNT2=$((COUNT2+1));
	   echo "    *** $COUNT2 extractable rar files ($COUNT0 total rars scanned)"
	   mkdir -p "${DSTDIR}" 2> /dev/null
	   ### unrar x $OVERWRITE "${FILEFULLPATH}" "${DESTINATION}${NEWRDIR}" |& grep . |& awk '{print "*    " $0;}' && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE, DST: $DESTINATION" >> "${EXTRACTED1}"
	   ### STATUS="FAIL"
	   STATUSFILE=/tmp/unrar3status-`date +%s`-`echo $$`
	   echo "FAIL" > $STATUSFILE
	   (unrar x $OVERWRITE "${FILEFULLPATH}" "${DSTDIR}" && (echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE, DST: $DESTINATION"; echo "SUCCESS" > $STATUSFILE;) >> "${EXTRACTED1}" || echo "[`date`][`date +%s`] Failed $0 on SRC: $SOURCE, DST: $DESTINATION - $FILEFULLPATH" >> ${DSTDIR}/failed-unrar3.txt) |& grep . |& awk '{print "*    " $0;}'
	   echo "$0|`date`/`date +%s`|`cat $STATUSFILE`|$SOURCE|$i --> $DESTINATION" >> /var/log/unrar123.log
	   ### added this to delete rars - start ###
	   if grep -q "^SUCCESS$" "$STATUSFILE"; then
	       TMPW="EXTRACTION SUCCESSFUL"
	       COUNT3=$((COUNT3+1));
		   echo "   *** Extracted Succesfully - along with $COUNT3 out of $COUNT2 extractable rars"
		   VV=0
		   for j in `unrar la -v "${FILEFULLPATH}"  | awk '/^Archive:/{$1="";print $0}' | sed 's/^[ \t]*//;s/[ \t]*$//'`; do
			   VV=$((VV+1))
			   DELETEVOL="$j"
			   ## DELETEVOLFULLPATH="$FULLDIR/$j"
			   (echo -n "+ ${VV} SUCCESSFUL UNRAR -> Deleting rar volume: ${DELETEVOL}: "
			   rm -f "${DELETEVOL}" && echo "deleted!" || echo "delete failed!") |  tee -a "${EXTRACTED1}"
		   done
	   else
	       TMPW="EXTRACTION FAILED"
	       COUNT4=$((COUNT4+1));
		   echo "   *** Failed to Extract - along with $COUNT4 out of $COUNT2 extractable rars"
		   echo "+ NOT SUCCESSFUL UNRAR -> Not deleting rar volume[s]"
	   fi
	   ### added this to delete rars - end ###
	   # delete the status file, so as to not fill up the /tmp folder
	   rm $STATUSFILE
	fi
	echo "   *** TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" | tee -a /var/log/unrar123.log
	echo "* ${FILEFULLPATH} : ${TMPW}" >> /var/log/unrar123.brief
done;
echo "* TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" >> /var/log/unrar123.brief
cat /var/log/unrar123.brief >> /var/log/unrar123.allbrief
IFS=$OLDIFS)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
* /usr/local/bin/rtunzip-any-currentfolder-deletezipsnrars.sh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#!/bin/bash
# this unzips everything into _ex, where zips are, then it unrars
# then it removes the zips and rars
MAIN_FOLDER=`pwd`
START_FOLDER=`readlink -f "$MAIN_FOLDER"`
(
# THIS PART OF THE SCRIPT IN THE () IS CALLED unzip123.zip (its alike to unrar2) where unrar2 unzips everything to an _Extracted folder in the same folder as where the rar file is, this will extract it to _ex
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo
# go to folder where the zip->rar->stuff structure is (my current folder)
cd "$START_FOLDER"
# save ifs
OIFS=$IFS
IFS=$'\n'
FOLDER_LIST=`(for i in $(find -type f | grep "\.zip$"); do dirname "$i"; done;) | sort | uniq`
# going thru every folder
ZIPS1=0; COUNT_OF_ZIPS1=0; GOOD_ZIPS1=0; BAD_ZIPS1=0;
COUNT_OF_ZIPS1=`find -type f | grep "\.zip$" | wc -l`
for CUR_FOLDER in $FOLDER_LIST; do
	echo "########################################################### [`date` - `date +%s` s]"
	echo "* Checking out ZIPS in $CUR_FOLDER "
	# get into dir
	cd "$CUR_FOLDER"
	# if the zips already been extracted lets skip this
	if [ -f .zip-extracted ]; then
		echo "* ZIPS ALREADY EXTRACTED: loggin attempt to it"
		cat .zip-extracted
		echo "[`date` - `date +%s` s] zip already extracted (just stepped over it) " | tee -a .zip-extracted | awk '{print "   " $0}'		
	else
		# mkdir for zips that contain more zips
		mkdir _ex
		# count of all good zips
		COUNT_OF_ZIPS=`find . -maxdepth 1 -type f | grep "\.zip$" | wc -l`
		GOOD_ZIPS=0
                BAD_ZIPS=0
	        for i in *zip; do 
                  ZIPS=$((ZIPS+1))
                  ZIPS1=$((ZIPS1+1))
		  unzip -o "$i" -d _ex | awk '{print "   " $0}'
		  if [ $? -eq 0 ]; then
		    # if extracted well then count up
		    GOOD_ZIPS=$((GOOD_ZIPS+1))
		    GOOD_ZIPS1=$((GOOD_ZIPS1+1))
                    #### DELETE ZIP IF SUCCESSFULL ####
                    rm -f "$i"
                    echo "* EXTRACTED SUCCESFULLY & DELETED: $i"
                  else
		    BAD_ZIPS=$((BAD_ZIPS+1))
		    BAD_ZIPS1=$((BAD_ZIPS1+1))
                    echo "* FAILED TO EXTRACT: $i"
		  fi
                echo "*** TOTALS IN CURRENT FOLDER `pwd`: $ZIPS zips/$COUNT_OF_ZIPS $GOOD_ZIPS good $BAD_ZIPS failed"
                echo "*** TOTALS IN RUN: $ZIPS1 zips/$COUNT_OF_ZIPS1 $GOOD_ZIPS1 good $BAD_ZIPS1 failed"
	       done;
		# hopefully extracted as many as there are zip files
		if [ ${COUNT_OF_ZIPS} -eq ${GOOD_ZIPS} ]; then
			echo "[`date` - `date +%s` s] Zip SUCCESS in this FOLDER  - Extracted $GOOD_ZIPS zips out of $COUNT_OF_ZIPS in $CUR_FOLDER folder " | tee -a .zip-extracted
                        # make this file so in future if we go over this folder we dont need to extract the zips again
                else
                       echo "[`date` - `date +%s` s] Zip FAIL in this FOLDER - Extracted $GOOD_ZIPS zips out of $COUNT_OF_ZIPS (Failed ${BAD_ZIPS}) in $CUR_FOLDER folder"
		fi
	fi
	echo;
	# get back to normal location, so loop can work again
	cd "$START_FOLDER"
done
IFS=$OIFS
echo "* check /var/log/unrar123 files to see how the next and final step of unrar and fixperming went"
echo 
) | tee -a /var/log/unzip123.log
echo "=========================="
echo "Running RTUNRAR2NFIX Twice"
echo "=========================="
#run unrar with fixperms twice (logs to /var/log/unrar123) - fix perms runs from within UNRAR2NFIX (which runs on current folder)
/root/scripts/UNRAR2NFIX-deleterars.sh
/root/scripts/UNRAR2NFIX-deleterars.sh
# remind of log
echo "========================"
echo "`basename $0` FINAL WORDS"
echo "========================"
echo "* Dont forget to check out /var/log/unzip123.log"
cp /var/log/unzip123.log /data/Main/Downloads/unzip123.txt
# so windows can see
unix2dos /data/Main/Downloads/unzip123.txt

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *