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
Code:
#!/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
Hello,
I'm stuck and confused as to why when I execute things form the command line it works but when in a script it doesn't.
My script:
### creating a lock on the console
touch /var/run/console.lock
chmod 600 /var/run/console.lock
echo "$User" >>... (2 Replies)
Howdie everyone...
I have a shell script RemoveFiles.sh
Inside this file, it only has two commands as below:
rm -f ../../reportToday/temp/*
rm -f ../../report/*
My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Hi everybody:
I usually use Mandriva distro (in my laptop), and I have made some scripts. These scripts work correctly but now, in other computer which is installed Ubuntu don't work, and I have this error message:
The script is:
.....
echo "Your option is:"
echo
read option
case... (1 Reply)
Hi there. I'm new to scripting in bash shell and I have this problem.
I'm trying to make a script that returns the greatest common divisor of two integer numbers according to Euclid's algorithm...
Here is, what I've done:
#!/bin/bash
m=$1
n=$2
while
do
if ; #line 8
then m=$m-$n... (1 Reply)
Hi All,
Using Expect script when I run it manually it works. But when I put the entry in crontab, the job is still running after 15 hours. The script was created as root. I don't think it's a permission issue. Any idea?
This is what I have under root crontab...
00 18 * * 1-5... (4 Replies)
Hi there,
the following script doesn't work. the first part works, then the second 'grep' fails with ': not found'. However, if I take out the second part (starting with the grep command) and put in a seperate script, it works.
everyone know what's wrong here? no two 'grep' in one script, that... (2 Replies)
I have a script that only works if I remove it from the looping scenario.
#!/bin/bash
# Set the field seperator to a newline
##IFS="
##"
# Loop through the file
##for line in `cat nlist.txt`;do
# put the line into a variable.
##dbuser=$line
echo "copying plugin..."
... (6 Replies)
i have this script and when i ejecute it, the console tell me this " sintax error line 41 unexpected element "}" "
is the sintaxis ok?
#!/bin/bash
if ;then
{
exit 0;
}
if ; then
{
sudo /etc/init.d/apache2 start;
sudo /etc/init.d/mysql start;
php5 &
nautilus... (3 Replies)
hi,
i am trying to run this script.the name of script is final.sh
after i run it:
#./final.sh &
i grep the command
# ps -a | grep bash
and i see more then one processes runing 3!!
Please use code tags
how can i solve this problem?
my target script must always run in... (8 Replies)
I am trying to run a script to make a simple modification to a number of similar files. The sed works, but after it runs and the differences are displayed, the script does not read ans to start a renaming script if the user answered Y or y.for i in "$@"
do
sed -f myfile.sed $i >$i.new
diff... (2 Replies)