simple shell script with elif and for nexxt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple shell script with elif and for nexxt
# 1  
Old 10-05-2009
simple shell script with elif and for nexxt

Hi!

I have here a simple script to change the advskew on carp interfaces. The first is working, but the part for status, where a for is within a if/else delivers everyime only the action for the value "prod". Even when i use type test or dev. Where did i made the mistake?

Code:
# $Log: switch-carp-priority.sh,v $
# Revision 1.2  2009/10/02 05:13:05  huth
# Änderungen im advskew in allen stages
#
# Revision 1.1  2009/10/01 12:27:11  huth
# initial checkin
#
#!/bin/sh
#Skript zur Veraenderung der Prioritaet der carp interfaces je stage

#Liste aller carp interfaces im produktiven stage
A="carp1" 
B='carp4'
C='carp5'
D='carp11'
E='carp12'
F='carp15'
G='carp19'
H='carp23'
I='carp30'

#Liste aller carp  interfaces im testing stage
testA='carp2 '
testB='carp3 '
testC='carp6 '
testD='carp10'
testE='carp14'
testF='carp17'
testG='carp20'
testH='carp29'
testI='carp34'

#Liste aller carp interfaces im development stage
devA='carp0 '
devB='carp7 '
devC='carp8 '
devD='carp9'
devE='carp13'
devF='carp16'
devG='carp35'

case "$1" in

    prod)
        for i in $A $B $C $D $E $F $G $H $I;do
            ifconfig "$i"
        done
        
        echo "Dies ist der aktuelle Stand im produktiven stage!"
        echo "Wollen Sie wirklich den advskew fuer den produktiven stage aendern? (y/n)"
        read Z
        echo "Geben Sie den neuen Wert für den advskew ein:"
        read X
        
        if [ "$Z"="y"i ] ; then
            for i in $A $B $C $D $E $F $G $H $I;do
                ifconfig "$i" advskew "$X"
               done
        else
            echo "Carpzustand wird nicht veraendert!"
        fi
        exit 0
        ;;
    
    test)
        for i in $testA $testB $testC $testD $testE $testF $testG $testH $testI;do
            ifconfig "$i"
        done
        
        echo "Dies ist der aktuelle Stand im testing stage!"
        echo "Wollen Sie wirklich den advskew fuer den testing stage aendern? (y/n)"
        read Z
        echo "Geben Sie den neuen Wert für den advskew ein:"
        read X
        
        if [ "$Z"="y" ] ; then
            for i in $testA $testB $testC $testD $testE $testF $testG $testH $testI;do
                   ifconfig "$i" advskew "$X"
               done
        else 
            echo "Carpzustand wird nicht veraendert!"
        fi
        exit 0
        ;;
    
    dev)
        for i in $devA $devB $devC $devD $devE $devF $devG $devH $devI;do
                ifconfig "$i"
        done
        
        echo "Dies ist der aktuelle Stand im development stage!"
        echo "Wollen Sie wirklich den advskew fuer den development stage aendern? (y/n)"
        read Z
        echo "Geben Sie den neuen Wert für den advskew ein:"
        read X
        
        if [ "$Z"="y" ] ; then
            for i in $devA $devB $devC $devD $devE $devF $devG $devH $devI;do
                   ifconfig "$i" advskew "$X"
               done
        else
            echo "Carpzustand wird nicht veraendert!"
        fi
        exit 0
        ;;
    status)
        echo "Welchen stage moechten Sie sich anschauen? (prod|test|dev)"
        read Y
        if [ "$Y"="prod" ]; then
            for i in $A $B $C $D $E $F $G $H $I;do
                ifconfig "$i"
            done
        elif [ "$Y"="test" ]; then
            for i in $testA $testB $testC $testD $testE $testF $testG $testH $testI;do
                ifconfig "$i"
            done
        elif [ "$Y"="dev" ]; then
            for i in $devA $devB $devC $devD $devE $devF $devG $devH $devI;do
                ifconfig "$i"
            done
        fi
        exit 0
    *)echo "Usage prod|test|dev"
        ;;
esac

# 2  
Old 10-05-2009
Hi.

All of your if / elif statements are wrong.

The = should have spaces before and after.

i.e.
bash code:
  1. if [ "$Z" = "y" ] ; then

Is this "i" after "y" intended:
bash code:
  1. if [ "$Z" = "y"i ] ; then
# 3  
Old 10-06-2009
Thx, it's working fine now, but i want to expand it. Maybe someone can help me with that. Is it possible to give this script a second parameter on the commandline instead of asking for the case and then for the advskew value? Something like that:

switch-carp-priority.sh prod 5

thx in advance

Alex
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help on simple shell script

Hello, I am running openmediavault on my Raspberry and I would like to use it as a backup FTP server of snapshots taken from my IP cams. So I get the network recorder to upload every 3 seconds a snapshot to the Raspberry. Everything works perfectly. I would need now a simple script that... (5 Replies)
Discussion started by: dcaccount
5 Replies

2. Shell Programming and Scripting

Simple Shell Script! Almost Done!

Hello, I am creating a shell script and I am almost done. I have certain things I want done in the shell but don't know how to finish it properly. Here is what I am aiming to do. I am aiming to have a shell that takes at least 3 parameters. The first two are the two words to replace (the... (3 Replies)
Discussion started by: ShellsNewb
3 Replies

3. Shell Programming and Scripting

Simple Shell Script? Someone help?

Write a shell script which adds up 10 numbers entered by the user and displays the result to the screen. You must use the read command to obtain the numbers from the user. Im a nooby noob (2 Replies)
Discussion started by: LinuxNubBrah
2 Replies

4. Shell Programming and Scripting

Help me with simple shell script.

Hello forum members, I have to redirect a output of command into a text file inside a script file but iam getting an errors.so please see below script and suggest me for corrections. #!/bin/ksh read IP_ADD echo nslookup $IP_ADD 2>&1| tee log1.txt cat /amex/gcst/siva/Testr/log1.txt... (6 Replies)
Discussion started by: rajkumar_g
6 Replies

5. Shell Programming and Scripting

Simple Shell Script

Hello Friends, I am writing a shell script which will grab a file if it exists and copies it to another folder and will append with current date. I have written but gives me error, plz help: -------------------------------------------- #!/usr/bin/sh source=/home/dev4rice/naveen/test1... (4 Replies)
Discussion started by: ganesh123
4 Replies

6. Shell Programming and Scripting

simple shell - how to get a parameter typed in a shell script

Hi, I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java myJavaprogram I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe... (4 Replies)
Discussion started by: cmitulescu
4 Replies

7. UNIX for Dummies Questions & Answers

IF THEN ELIF question in BOURNE SHELL

Hi, I get an error when executing this sample script. #!bin/sh if ; then echo "you need to enter the release as the first parameter" elif ; then echo "HI how are you ABC" echo "Hi how are you XYZ" echo " hi how are you all" else echo "using the $1 as input parameter" fi i get... (4 Replies)
Discussion started by: arun_st
4 Replies

8. Shell Programming and Scripting

Please Help On Simple Shell Script

This is an assignment I have to do everyone but I was viewing the threads and I assumed that I could write this assignment simpler than what My instructor is directing.. Here is the Assignment This shell script has the following specifications: - It must be named: "printpasswd." - It must... (1 Reply)
Discussion started by: dmosheye
1 Replies

9. Shell Programming and Scripting

need a simple shell script

Hi, I am new to unix as well as shell programming. Any body can provide me a simple shell script which should copy/transfer/fetch a file(using FTP)from remote server to local system.and it should log the details when it was fetched.If there is any error,the error msg should log in log... (1 Reply)
Discussion started by: Mar1006
1 Replies

10. Shell Programming and Scripting

A Simple shell Script

Hi there. im creating a shell script which helps me perform simple functions when i use it, but there are still two functions which i cannot figure out yet. 1) how can I count the number of occurences of a certain file within the whole file system? (filename supplied as an argument.) 2) How... (2 Replies)
Discussion started by: provo
2 Replies
Login or Register to Ask a Question