Hello,,
Im verry new to scripting and have some problems with this script i made..
What it does:
It checks a directory for a new directory and then issues a couple of commands.
checks sfv - not doing right now
checks rar - it checks if theres a rar file and when there is it skips to the next command. when there isnt it will rar the files in the directory and create an sfv file. [commented becuase doenst work]
checks par - it checks for par2 files and when there are no pars it will create them.
post to usenet
My problem:
When i uncomment the rarring part it will rar a directory with files in it.. But when the directory has subdirectorys with rars it also rars the directory and files instead of skipping.
The script works without the rar part but i need it to rar unpacked files..
It looks like the grep part doenst work if there are subdirectorys.. I hope someone here can make this script work..
Thx in advance
#!/bin/bash -x
echo start Autopost script...
#Monitor Path
checkpath="/home/upload"
#Monitor Folder for activity
ignore_folder="sample,Sample"
inotifywait --monitor --format %f -e moved_to -e create $checkpath | while read releasedir; do echo "New directory detected: Found $releasedir";
which cksfv >/dev/null
#Check SFV
cd "$checkpath/$releasedir"
echo "Checking $checkpath/$releasedir for SFV Please wait...";
if [ "$1" == "" ]; then
echo -ne ""
else
if [ -d "$1" ]; then
cd "$1"
else
echo $1 is not a directory
exit 2
fi
fi
ignore_folder=$(echo $ignore_folder | sed -e 's/\,/\ -e\ /g')
start_dir=$(pwd)
find -type d |grep -v -e $ignore_folder | while read path
do
if find "$path" -maxdepth 0 -empty | read; then
echo -e "INFO There are no files present in $releasedir"
else
result=$(ls -al "$path" |egrep '.*\.sfv')
if [ "$result" == "" ]; then
echo -e "WARNING! No sfv file present in $releasedir.
Skipping directory..."
else
cd "$path"
# echo result=$(cksfv -f *.sfv 2>/dev/null)
# #Create rar Files if rar exist skip
# files=$(ls -al "$checkpath/$releasedir/$path" |egrep '.*\.rar')
# if [ "$files" == "" ]; then
# echo -e "No rar files present in $releasedir. Going to rar $releasedir"
# cd "$checkpath/$releasedir/$path"
#
# rar a "$releasedir".rar -v50000k -vn -r -m0 -ep -df -cl "$checkpath/$releasedir/$path"/*
#
# filename=$(ls -1 "$checkpath/$releasedir/$path" |egrep '.*\.rar')
# cksfv -b "$checkpath/$releasedir/$path"/* > "${filename%.*}".sfv
#
# else
# echo -e "RAR found:$files"
# echo -e "Skip $releasedir"
# fi
#Create Par Files if par exist skip
files=$(ls -al "$checkpath/$releasedir/$path" |egrep '.*\.par2')
if [ "$files" == "" ]; then
echo -e "No par2 files present in $releasedir. Going to par2 the shit out of
$releasedir"
cd "$checkpath/$releasedir/$path"
filename=$(ls -1 "$checkpath/$releasedir/$path" |egrep '.*\.sfv')
echo $filename
par2create -r5 -n7 -m500 "${filename%.*}".par2 "$checkpath/$releasedir/$path"/*
else
echo -e "PAR2 files found..Skip $releasedir"
fi
if [ $? -eq 0 ]; then
echo -e "OK...No errors detected in $releasedir"
echo "Checking for more directorys.. Please wait.."
else
echo -e "\nERROR! SFV inconsistency detected in
$releasedir"
echo -e "\t $result"
echo -ne "\n"
exit
fi
cd $start_dir
fi;
fi
done
echo "Posting $releasedir Please wait.."
python /home/newsmang/poster.py -c /home/newsmang/sample.conf -f "$releasedir" "$checkpath/$releasedir"/* "$checkpath/$releasedir"/cd1/* "$checkpath/$releasedir"/cd2/* "$checkpath/$releasedir"/cd3/* "$checkpath/$releasedir"/sample/* "$checkpath/$releasedir"/subs/* "$checkpath/$releasedir"/CD1/* "$checkpath/$releasedir"/CD2/* "$checkpath/$releasedir"/CD3/* "$checkpath/$releasedir"/Sample/* "$checkpath/$releasedir"/Subs "$checkpath/$releasedir"/Cd1/* "$checkpath/$releasedir"/Cd2/* "$checkpath/$releasedir"/Cd3/* "$checkpath/$releasedir"/SAMPLE/* "$checkpath/$releasedir"/SUBS "$checkpath/$releasedir"/DiSC1/* "$checkpath/$releasedir"/DiSC2/* "$checkpath/$releasedir"/DiSC3/*
echo "$releasedir Posted.."
echo "Waiting for new release. Scanning Folder..."
done