Elseif & for condition in AIX


 
Thread Tools Search this Thread
Operating Systems AIX Elseif & for condition in AIX
# 1  
Old 04-24-2015
Elseif & for condition in AIX

I'm using the below statements in my script

Code:
if [$selection -ge 0] && [$selection -le 7] then
   sqlplus sysadm/abcdefgh12@${dbarr[idx]} @/u1/scripts/ResetPswd.sql
elif [$selection == 8] then
   for idx in 0 1 2 3 4 5 6 7
      do
         sqlplus sysadm/abcdefgh12@${dbarr[idx]} @/u1/scripts/ResetPswd.sql
      done
else
   exit
fi

It give me the error
Code:
`elif' unexpected

Can someone please help me? Also please let me know if the for condition is correct. for condition I meant was to execute the command for all the values (idx) 0 to 7
# 2  
Old 04-24-2015
Code:
if [ "${selection}" -ge 0 ] && [ "${selection}" -le 7 ]; then

Code:
elif [ "${selection}" -eq 8 ]; then

# 3  
Old 04-24-2015
Can I also suggest that you take the credentials out of your sqlplus command line. Anyone running a simple ps will be able to see them whilst your database connection is active.

It might only be a short time, but if this account is a DBA (which I'm guessing that it is) then you are effectively shouting the out the number for a combination lock on your most secure safe. If no-one is listening, then you get away with it. If someone hears, it depends on their integrity if they do something with it.



Robin
# 4  
Old 04-24-2015
If the variable idx is not defined earlier in the script, where we can't see it, the sqlplus statement in the second line above will fail.

Last edited by RudiC; 05-06-2015 at 05:07 AM.. Reason: typo
# 5  
Old 05-05-2015
Try this...

Code:
if [[ $selection -ge 0 && $selection -le 7 ]]
then
        sqlplus sysadm/abcdefgh12@${dbarr[idx]} @/u1/scripts/ResetPswd.sql
elif [[ $selection == 8 ]]
then
        for idx in 0 1 2 3 4 5 6 7
        do
                sqlplus sysadm/abcdefgh12@${dbarr[idx]} @/u1/scripts/ResetPswd.sql
        done
else
        exit
fi

# 6  
Old 05-07-2015
Again, I would suggest moving the credentials out of the sqlplus command line, perhaps like this:-
Code:
if [[ $selection -ge 0 && $selection -le 7 ]]
then
        sqlplus sysadm/abcdefgh12@${dbarr[idx]} @/u1/scripts/ResetPswd.sql
elif [[ $selection == 8 ]]
then
        for idx in 0 1 2 3 4 5 6 7
        do
            sqlplus <<-EOSQL
               sysadm/abcdefgh12@${dbarr[idx]}
               @/u1/scripts/ResetPswd.sql
            EOSQL                 # Tab indented only!
        done
else
        exit
fi

You don't want to be broadcasting your most secure user credentials.



Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

awk question: How to print condition of NR & NF together.

Experts: LINE1 :This is line one The FIRST line of the file. LINE2 :This is line two LINE3 :This is line three with 8 fileds LINE4 :This is line four LINE5 :This is line five LINE6 :This is line six with 8 fileds I want to delete line 1, and then process the file and want to print lines... (2 Replies)
Discussion started by: rveri
2 Replies

3. Shell Programming and Scripting

Help regarding if condition in AIX

Hi, My requirement is to check wheather some csv files have mandatory columns value as empty if empty log a error message or set a flag. The problem here is that the column number varies for different CSVs hence we can not hardcode $1 or $3 like this in the awk command hence we are reading a... (5 Replies)
Discussion started by: sukhdip
5 Replies

4. Shell Programming and Scripting

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. ./sample_oracle_tradescope.sh: 25: showDEFAULTUsage: not found ... (6 Replies)
Discussion started by: oracle_coorgi
6 Replies

5. 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

6. 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

7. AIX

How to upgrade AIX Firmware & TL Maintenance Level in AIX

Steps to upgrade AIX TL ( technology Level ) / Maintenance Level in AIX ( including Firmware HMC VIOS ) This article or post covers upgrades for - Hardware Management Console ( HMC ) - Firmware ( also known as microcode ) - VIO ( Virtual I/O Server = PowerVM ) - AIX Version, Technology... (2 Replies)
Discussion started by: filosophizer
2 Replies

8. Shell Programming and Scripting

combination between || and && in IF condition with ksh

Dear All, Please advice about this issue. when i run this line in a script if && || && || && if i enter $x = test3 and $y = test1 the If condition apply while it should not Best Regards (2 Replies)
Discussion started by: islam.said
2 Replies

9. 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