Nested If in Unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Nested If in Unix
# 1  
Old 06-20-2011
Nested If in Unix

Hi!!
Code:
LookVar=`find . -name "${input}" | wc -w`
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
echo "Oops!The services are not available in the source"
bye
EOF
fi
fi

I' ve written a script as above but while executing it throws an error
nfscript.sh[6]: 0403-057 Syntax error at line 37 : `fi' is not expected.

could anyone please help me in this..

Last edited by vbe; 06-20-2011 at 11:43 AM.. Reason: code tags + typos... And use plain english please!Read the rules again
# 2  
Old 06-20-2011
Since your script isnt complete or we are missing some more explanation it will be hard to help you... (26 lines here...)
# 3  
Old 06-20-2011
Sry
this is de entire script

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
echo "Oops!The services are not available in the source"
bye
EOF
fi
fi
if [ $LookVar -eq 0 ]
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
echo "Oops!The services are not available in the source"
bye
EOF
fi
fi
done

Moderator's Comments:
Mod Comment Please start using [CODE] tags for code listings, console ouput, ... Also, indenting your code would make it much more readable, and thus easier to debug.

Last edited by pludi; 06-20-2011 at 12:02 PM..
# 4  
Old 06-20-2011
Quote:
Originally Posted by Afsana
Sry
this is de entire script

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
echo "Oops!The services are not available in the source"
bye
EOF
fi
fi
if [ $LookVar -eq 0 ]
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
echo "Oops!The services are not available in the source"
bye
EOF
fi
fi
done

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 06-20-2011 at 12:03 PM.. Reason: once again - please use code tags!
# 5  
Old 06-21-2011
pls help me.

this is the code

. /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
fi
chmod 775 ./*
cd $Path
if [ $SoLookVar -eq 0 ]
then
echo "Oops!The services are not available in the source"
bye
EOF
fi
fi
done

if i execute this, it throws an error

nwfscript.sh[5]: 0403-057 Syntax error at line 36 : `fi' is not expected.
# 6  
Old 06-21-2011
As the first if condition present b/w the EOF, then it is not able to recognize the fi

Code:
 
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

This User Gave Thanks to itkamaraj For This Post:
# 7  
Old 06-21-2011
thanks a lot itkamaraj i made some changes in the script now my script looks like below

. /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 ./*
fi
bye
EOF
chmod 775 ./*
cd $Path
if [ $SoLookVar -eq 0 ]
then
echo "Oops!The services are not available in the source"
fi
bye
EOF
fi
done


but when this is executed i get the following error

/Informatica/samb2b06092011
sam1
1
?Invalid command
?Invalid command
?Invalid command
?Invalid command
nwfcript.sh[29]: test: 0403-004 Specify a parameter with this command.
nwfcript.sh[33]: bye: not found.
nwfcript.sh[34]: EOF: not found.
dam1
1
?Invalid command
?Invalid command
?Invalid command
?Invalid command
nwfcript.sh[29]: test: 0403-004 Specify a parameter with this command.
nwfcript.sh[33]: bye: not found.
nwfcript.sh[34]: EOF: not found.

Pls help me in this. Im a beginner in unix shell scripting. I dono wat to do
 
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