Nested If in Unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Nested If in Unix
# 8  
Old 06-21-2011
Please use code tags!!! and no bumping up either or mods will not be your friend anymore...

Try this:

Code:
#!/bin/ksh
. /Informatica/var.ini
echo "Change directory to location where the services exit .."
cd $Path
echo $Path
cat $FILE_PATH | while read input
do
	echo $input
	LookVar=`find . -name "${input}" | wc -w`
	echo $LookVar
	if [ $LookVar -ge 1 ]
	then
		cd $input
		rm -f *
		ftp -n -i $HostName << EOF
		quote USER $User
		quote PASS $Password
		cd $Path
		SoLookVar=`find . -name "${input}" | wc -w`
		echo $SoLookVar
		if [ $SoLookVar -ge 1 ]
		then
			cd $input
			mget ./*
			bye
			EOF
			chmod 775 ./*
			cd $Path
#fi		if [ $SoLookVar -eq 0 ]		then
		else
			echo "Oops!The services are not available in the source"
			bye
			EOF
		fi
#fi		#if [ $LookVar -eq 0 ]
	else
					#then
		mkdir $input
		cd $input
		ftp -n -i $HostName << EOF
		quote USER $User
		quote PASS $Password
		cd $Path
		SoLookVar=`find . -name "${input}" | wc -w`
		echo $SoLookVar
		if [ $SoLookVar -ge 1 ]
		then
			cd $input
			mget ./*
			bye
			EOF
			cd $Path
			chmod -R 775 $input
			cd $Path
#fi		#if [ $SoLookVar -eq 0 ]		#then
		else
			echo "Oops!The services are not available in the source"
			bye
			EOF
		fi
	fi
done

All I did is commented out a test of no use IMHO replacing it by a "else"
# 9  
Old 06-21-2011
ftp doesnt support if

Hi
I found that ftp does not support if condtion
can anyone pls tell me how can i check whether the file is present in the remote server by using ftp
I can use only ftp not ssh

Last edited by Afsana; 06-21-2011 at 08:08 AM.. Reason: found another way
# 10  
Old 06-21-2011
I usually use mget *.what to a local empty directory and test after if still empty...
# 11  
Old 06-21-2011
Hi vbe
thanks
cud u pls give me some example
# 12  
Old 06-21-2011
here the simple code to check where file exist on server or not

Code:
 file_needs_to_search="abc,txt"
 local_dir="/tmp"
 ftp_dir="/tmp/asd"
         ftp -n -i $HostName << EOF
        quote USER $User
        quote PASS $Password
        cd ${ftp_dir}
            lcd ${local_dir}
        get ${file_needs_to_search}
        bye
        EOF
        ftpstat=`ls -lrt ${local_dir}/${file_needs_to_search}| wc -l`
        
     if [ ${ftpstat} -eq 0 ]
    then
        echo " File not exist on ftp sevre"
    else
        echo " File exist on ftp server"
                # here you can do with file 
        fi

# 13  
Old 06-21-2011
thank u
sry for the inconvenience
i need to chck whether a dir exists in remote server
im very sry
cud anyone help me in this
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Convert CSV file to nested XML file using UNIX/PERL?

we have a CSV which i need to convert to XML using Perl or Unix shell scripting. I was able to build this XML in oracle database. However, SQL/XML query is running for long time. Hence, I'm considering to write a Perl or shell script to generate this XML file. Basically need to build this XML... (3 Replies)
Discussion started by: laknar
3 Replies

2. Shell Programming and Scripting

Nested if else

Hi, i m trying to create script which logic is like below. if ; then x=`cat /tmp/testoutput.log | grep STOP | wc -l` y=`cat /tmp/testoutput.log | grep RUN | wc -l` if ; then echo "process stop" if ; then echo "process running " else echo "file not found" fi ----------------... (2 Replies)
Discussion started by: tapia
2 Replies

3. Shell Programming and Scripting

Optimize the nested IF

Hi, I have to assign a value for a varaiable based on a Input. I have written the below code: if then nf=65 elif then nf=46 elif then nf=164 elif then nf=545 elif then nf=56 elif then (3 Replies)
Discussion started by: machomaddy
3 Replies

4. Shell Programming and Scripting

Nested case

Hi there, I have nested case in my script. I am asking user, want to continue? if user press y/Y then my inner case should continue, rather than that my code start from beginning. I would like to continue my inner case until user press n or N. Is any one tell me how can I do? Thanking You,... (2 Replies)
Discussion started by: kasparov
2 Replies

5. UNIX for Dummies Questions & Answers

How to use nested ifs in unix?

how to use nested ifs in unix (1 Reply)
Discussion started by: pratima.kumari
1 Replies

6. Shell Programming and Scripting

Nested loop in Unix

Hi, I have the following script which is two while loops, but it is working only for the Inner loop without going back to the outer loop. the aim of this script is to remove data files from memory after each five times for each setting of the rotate parameter #!/bin/csh set hdir =... (1 Reply)
Discussion started by: moon218
1 Replies

7. Shell Programming and Scripting

Nested Case in UNIX script

Hi I wanted to know if we can write a nested case in UNIX script. Something like following - Case ${sDB} in Srvr1) case ${sSchema} Sch1) DBusr=Username1 DBPwd=Pwd1 ;; Sch2) DBusr=Username2 ... (1 Reply)
Discussion started by: sumeet
1 Replies

8. Shell Programming and Scripting

can nested SQl be run in Unix Script?

can nested SQl be run in Unix Script? I tried some and found only simply sql(one select) can work well in unix script. (21 Replies)
Discussion started by: YoYo
21 Replies

9. Shell Programming and Scripting

nested loop

I have two do loops. When I break of the inner loop it doesn't go back to the outer loop but exit the program. (5 Replies)
Discussion started by: chinog
5 Replies

10. Shell Programming and Scripting

Nested calls

Hi all, I have two questions: 1. I have a script (call it A) that call another script (call it B) which in turn call another script (call it C). The strange thing is that when script C hangs script A exists (i.e., will not appear when I call ps command to list all the running processes). Is my... (6 Replies)
Discussion started by: omran
6 Replies
Login or Register to Ask a Question