if elseif fi


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting if elseif fi
# 1  
Old 12-30-2010
if elseif fi

Hi,

Ihave shifted this thread which i posted in linux forum to here if i am fault please correct me.

When i excute this below script i am getting the follwing error can any one please look into it for persual.

Code:
 
./sample_oracle_tradescope.sh: 25: showDEFAULTUsage: not found
[: 36: =: unexpected operator
[: 36: Illegal number: 0$
[: 36: oracleDBMIGRATORSCRIPT: unexpected operator
./sample_oracle_tradescope.sh: 38: oracleDBMIGRATORSCRIPT: not found
./sample_oracle_tradescope.sh: 39: exp: not found
./sample_oracle_tradescope.sh: 40: Syntax error: "(" unexpected

Code:
#!/bin/sh 
argCount=0
#sqlserver_path=C:/Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/Backup/
mysql_path=$USER_INSTALL_DIR$
#for %%i in ($*); do /A argCount+=1
#if %argCount% EQU 0 (
# call :showDEFAULTUsage %0%
# goto:_EOF
#)
for i in $*; do 
/A argCount+=1
done
if [ $argCount -eq 0 ];then
echo "There are no rejected records." >> /opt/oracle/Public/test.txt
fi
if [ $argCount -eq 0 ];
then
showDEFAULTUsage $0$;
fi
if [ $1 = Oracle ]
then 
echo "Oracle"
elif
[ $argCount$ -ne 9 ]
then
[ showORACLEUsage $0 ]
else
[ oracleDBMIGRATORSCRIPT $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 ]
fi
oracleDBMIGRATORSCRIPT
exp 'system/$2@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=$3)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=$4)))' file=$8.exp owner=$8 consistent=y statistics=none log=/export_db_$8.log
echo CONNECT system/$5@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=$6)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=$7))) >$~1.tmp
echo drop user $9 cascade;>>$~1.tmp
echo create user $9 identified by $9; >>$~1.tmp
echo grant all privileges to $9; >>$~1.tmp
echo EXIT; >>$~1.tmp
sqlplus /nolog @$~1.tmp
imp 'system/$5@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=$6)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=$7)))' file=$8.exp log=/import_db_$9.log fromuser=$8 touser=$9
EOF
showDEFAULTUsage
echo [USAGE]: $~1 "DB TYPE(mysql|oracle|sqlserver|sybase)" "DB PARAMS"
EOF
showORACLEUsage
echo [USAGE]: $~1 "DB TYPE" "SOURCE DB SYSTEM PWD" "SOURCE DB HOST" "SOURCE DB SID" "TARGET DB SYSTEM PWD" "TARGET DB HOST" "TARGET DB SID" "SOURCE SCHEMA" "TARGET SCHEMA"
EOF
EOF

# 2  
Old 12-30-2010
Are "exp" and "imp" binary programs, shell scripts, or oracle procedures?

Do the "$" parameters to "exp" and "imp" come from the shell parameters or are they part of the syntax. If they are between single quote characters they will not be substituted by shell.

Btw. Your main syntax errors are because you have not declared shell procedures correctly.
For example (one of three places with the problem):
Quote:
showDEFAULTUsage
echo [USAGE]: $~1 "DB TYPE(mysql|oracle|sqlserver|sybase)" "DB PARAMS"
EOF
Should probably be:
Code:
showDEFAULTUsage ()
{
echo "[USAGE]: $~1 DB TYPE(mysql|oracle|sqlserver|sybase) DB PARAMS"
}

Btw: I have never seen $~1 in a shell script. Others may know whether it is a valid variable and what it means.


This chunk of code is overcomplicated has many syntax errors:
Quote:
if [ $1 = Oracle ]
then
echo "Oracle"
elif
[ $argCount$ -ne 9 ]
then
[ showORACLEUsage $0 ]
else
[ oracleDBMIGRATORSCRIPT $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 ]
fi
Maybe should be something like this: We display an error and exit if the parameters are invalid or missing. We drop through to the final command.

Code:
if [ ! "$1" = "Oracle" ]
then
        showORACLEUsage
        exit
fi
echo "Oracle"
#
if [ ${argCount} -ne 9 ]
then
         showORACLEUsage
         exit
fi
#
oracleDBMIGRATORSCRIPT $0 $1 $2 $3 $4 $5 $6 $7 $8 $9


This bit is unlikely to work:
Quote:
for i in $*; do
/A argCount+=1
done
Maybe try:
Code:
argCount=$#


This line is an irrelevant piece of Microsoft Batch code and should be commented out:
Quote:
mysql_path=$USER_INSTALL_DIR$

Last edited by methyl; 12-30-2010 at 09:35 AM..
# 3  
Old 01-04-2011
hi
i have given variable 1 to 9
Code:
 
and $2 variable is password
as $2 is password and contains abc123$ password i am unable to login invaild password due to $(symbol), how can i bypass or other way to pass abc123$ for that variable

Code:
 
 
exp system/$2@'(DESCRIPT................
..............

thanks for the responce in spite of different posting
thanks once agin
# 4  
Old 01-04-2011
Quote:
Originally Posted by oracle_coorgi
hi
i have given variable 1 to 9
Code:
 
and $2 variable is password
as $2 is password and contains abc123$ password i am unable to login invaild password due to $(symbol), how can i bypass or other way to pass abc123$ for that variable

Use double quotes on your exp call ($ vars are expanded when within double quotes but are kept as-is in single):
Code:
exp "system/$2@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=$3)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=$4)))" file=$8.exp owner=$8 consistent=y statistics=none log=/export_db_$8.log

# 5  
Old 01-04-2011
Hi Below script is throwing an exception elfi not correct at line no 21.

Can you please have a look at script and advice what is wrong in below script?
Code:
echo "1.FILE PERMISSION"
echo "2.FILE INODE NUMBER"
echo "3.FILE SIZE"
echo "4.FILE OWNER"
echo " Enter what do you want from the option"
read num
if [ $num -eq 1 ]
echo " Enter filename you want permissions for : "
read file1
if [ -f $file1 ]
then
echo " FILE PERMISSIONS for $file1 = `ls -ltr $file1 | awk '{print $1}'` "
exit 0
else
echo " FILE NOT FOUND"
exit 1
fi
elif [ $num -eq 2 ]
echo " Enter filename for which you want INODE NUMBER for : "
read file1
if [ -f $file1 ]
then
echo " FILE INODE NUMBER for $file1 = `ls -il $file1 | awk '{print $1}'` "
exit 0
else
echo " FILE NOT FOUND"
exit 2
fi
elif [ $num -eq 3 ]
echo " Enter filename for which you want SIZE  : "
read file1
if [ -f $file1 ]
then
echo " FILE INODE NUMBER for $file1 = `ls -ltr $file1 | awk '{print $5}'` "
exit 0
else
echo " FILE NOT FOUND"
exit 3
fi
elif [ $num -eq 4 ]
echo " Enter filename for which you want OWNER for : "
read file1
if [ -f $file1 ]
then
echo " FILE OWNER for $file1 = `ls -l $file1 | awk '{print $9}'` "
exit 0
else
echo " FILE NOT FOUND"
echo 4
fi
else
echo "YOu have not chosen from the list"
exit 0
fi


Last edited by Franklin52; 01-05-2011 at 03:54 AM.. Reason: Please use code tags and indent your code.
# 6  
Old 01-05-2011
There were a number of issues (missing "then", orphaned "elif" , wrong answer displayed etc.). In the end it is much easier to use a "case" statement for the options.
For rapid testing I have surrounded this example menu in a do-done loop and removed lots of "exit" statements. There are now no "else" or "elif" statements in the script which makes it much easier to follow.

Code:
while true
do

echo ""
echo "1.FILE PERMISSION"
echo "2.FILE INODE NUMBER"
echo "3.FILE SIZE"
echo "4.FILE OWNER"
echo " Enter what do you want from the option"
read num

case $num in
1)
    echo " Enter filename you want permissions for : "
    read file1
    if [ ! -f $file1 ]
    then
        echo " FILE NOT FOUND"
    fi
    echo " FILE PERMISSIONS for $file1 = `ls -ltr $file1 | awk '{print $1}'` "
    ;;
2)
    echo " Enter filename for which you want INODE NUMBER for : "
    read file1
    if [ ! -f $file1 ]
    then
        echo " FILE NOT FOUND"
    fi
    echo " FILE INODE NUMBER for $file1 = `ls -il $file1 | awk '{print $1}'` "
    ;;
3)
    echo " Enter filename for which you want SIZE  : "
    read file1
    if [ ! -f $file1 ]
    then
        echo " FILE NOT FOUND"
    fi
    echo " FILE SIZE for $file1 = `ls -lad $file1 | awk '{print $5}'` "
    ;;
4)
    echo " Enter filename for which you want OWNER for : "
    read file1
    if [ ! -f $file1 ]
    then
        echo " FILE NOT FOUND"
    fi
    echo " FILE OWNER for $file1 = `ls -lad $file1 | awk '{print $3}'` "
    ;;
*)
    echo "You have not chosen from the list"
    exit 0
    ;;
esac
#
done



@gcvinayak
Please start a new thread in future. Just realised that this is a completely different subject.

Last edited by methyl; 01-05-2011 at 07:57 AM..
This User Gave Thanks to methyl For This Post:
# 7  
Old 01-06-2011
Thank you for your answer methyl. Yes, i will post in different thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. AIX

Elseif & for condition in AIX

I'm using the below statements in my script if && then sqlplus sysadm/abcdefgh12@${dbarr} @/u1/scripts/ResetPswd.sql elif then for idx in 0 1 2 3 4 5 6 7 do sqlplus sysadm/abcdefgh12@${dbarr} @/u1/scripts/ResetPswd.sql done else exit fi It give me... (5 Replies)
Discussion started by: Pandee
5 Replies

2. Programming

Problem with IF ELSEIF and GOTO statements in FORTRAN

Hi I am reading a book about Fortran 90 and I write the following code, to test my understanding of the first chapter. I have a problem with the last section of the code with deals with an IF, ELSEIF, and GOTO statements. Here is my Code PROGRAM sim ! This code is used to solve two... (3 Replies)
Discussion started by: faizlo
3 Replies

3. UNIX for Dummies Questions & Answers

If Then ElseIf Script - Confusion Around Expression's Syntax

Hello, I am relatively new to UNIX scripting and am learning a lot. I have already tried several searches on this website and have tried various syntax options suggested to no avail. I am obviously not writing the script correctly. I really do appreciate any and all the help. Below is an... (8 Replies)
Discussion started by: dqrgk0
8 Replies

4. Linux

if elseif fi

Hi all, This is my first post in this forum, can i request you to guide, where i am going wrong with the error below. 34: Syntax error: "fi" unexpected (expecting "then") #!/bin/sh argCount=0 mysql_path=$USER_INSTALL_DIR$ for i in $*; do /A argCount+=1 done if ;then echo... (2 Replies)
Discussion started by: oracle_coorgi
2 Replies

5. Shell Programming and Scripting

elseif in csh

I have been using the if statement in csh like this if ( $opt1 == 1 ) then ..... elseif ( $opt2 == 1 ) then ...... endif Seems to work, but got Badly placed ()'s. When I used a space in the elseif, a space between the 'else' and the 'if' it worked (0 Replies)
Discussion started by: kristinu
0 Replies

6. Shell Programming and Scripting

Awk if elseif syntax error

Below is the code. nawk -F "|" 'FNR==NR{a=$3 OFS $4 OFS $5 OFS $6;next} {\ if ($5 in a)\ {print $1,"ABC",$5,"I",a, $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2"-"$3"-"$4} ; \ elseif ($5=="g")\ print $1,"ABC",$5,"I",$5 OFS OFS OFS OFS $2,$3,$4 OFS OFS OFS OFS OFS... (8 Replies)
Discussion started by: pinnacle
8 Replies
Login or Register to Ask a Question