Help with script.. it Just doesn't work


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with script.. it Just doesn't work
# 1  
Old 02-23-2010
Help with script.. it Just doesn't work

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

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

# 2  
Old 02-23-2010
We need to get certain quirks out of the script first to make it understandable.

1) Please remove the semi-colon at the end of any line where it is the last character. This is unix script not Oracle.

2) I am nervous about the line spacing as posted. Was this script created as a unix text file using a unix text editor?
If you do this command does every line end in a $ character (meaning standard unix line terminator)?

Code:
sed -n l the_name_of the_script

3) Tip: If you have called a script with variables, save those variables in meaningfully-named environment variables as soon as possible in case a subsequent command changes those $n variables or the script just becomes difficult to follow. In this script we have no ideas what is in $1 except that it is a directory name and that if it is not provided we can proceed with the script after displaying a meaningless message.

Quote:
if [ "$1" == "" ]; then
echo -ne ""
Perhaps better?
Code:
if [ "$1""X" = "X" ]; then
	echo "Usage: scriptname <directory_name>"
             exit 1



4) Please re-test after removing extraneous semi-colons and removing any extraneous carriage-return characters from the script file (if present). Then please re-post the current version of the script showing exactly how it was called and all output produced (including any error messages).

5) Each time you issue an "ls" where the files may not be present, you need to stop the command failing by redirecting the error channel.

Quote:
result=$(ls -al "$path" |egrep '.*\.sfv')
Code:
result=$(ls -al "$path" 2>/dev/null |egrep '.*\.sfv')

6) Within the commented-out "rar" section, this line is strange:

Quote:
# if [ "$files" == "" ]; then
What do you want the test to achieve?

Last edited by methyl; 02-23-2010 at 08:49 PM.. Reason: ls quirks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read in script doesn't work

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)
Discussion started by: wbport
2 Replies

2. Shell Programming and Scripting

[Solved] Script doesn't work..help?

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)
Discussion started by: zigizag
8 Replies

3. Shell Programming and Scripting

my script doesn't work :(

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)
Discussion started by: keiserx
3 Replies

4. Shell Programming and Scripting

Script doesn't work in loop but does if not

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)
Discussion started by: bugeye
6 Replies

5. Shell Programming and Scripting

two grep in one script doesn't work?

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)
Discussion started by: monkey77
2 Replies

6. Shell Programming and Scripting

Expect script doesn't work under crontab

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)
Discussion started by: samnyc
4 Replies

7. Shell Programming and Scripting

gcd.sh script doesn't work...

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)
Discussion started by: kantze
1 Replies

8. Shell Programming and Scripting

script doesn't work in another distribution

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)
Discussion started by: tonet
1 Replies

9. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

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)
Discussion started by: cheongww
2 Replies

10. Shell Programming and Scripting

command line work script doesn't

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)
Discussion started by: larry
2 Replies
Login or Register to Ask a Question