Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
I am trying to create a script that starts and stops MQ Queue managers but I receive 'illegal variable name' when I try to run the restart switch. Any ideas? ...
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    14

    illegal variable name

    I am trying to create a script that starts and stops MQ Queue managers but I receive 'illegal variable name' when I try to run the restart switch. Any ideas? Must be something simple I am missing. It breaks at the while loop.

    #!/bin/csh
    #
    # startmq This shell script takes care of starting and stopping
    # MQ Queue Managers
    #
    # chkconfig: - ## ##
    # description: startmq is used to start, stop and restart Websphere MQ Queue Managers.
    # The variable QM needs to be set to the name of the Queue Manager.

    set QM=TEST

    set temp=""
    switch ($1)
    case start
    echo "Starting MQ Queue Manager: "
    # Start MQ queue managers that were created with altiris
    strmqm $QM
    breaksw
    case stop
    endmqlsr -m $QM
    endmqm $QM
    breaksw
    case restart
    echo "Restarting MQ Queue Manager: "
    endmqlsr -m $QM
    endmqm $QM
    while ($temp == "")
    set temp=$(dspmq | grep Ended)
    end
    strmqm $QM
    breaksw
    default
    echo "Usage: $0 {start|stop|status|restart}"
    endsw

  2. #2
    Just Joined!
    Join Date
    May 2008
    Posts
    14
    So are people not responding because it is really easy or they have no clue?

  3. #3
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    1) The construct $( ... ) is a Bourne shell family construct.

    2) Variables in expressions should usually be quoted.

    3) Elements in expressions with "==" will likely be treated as numbers.

    4) set echo can be useful in debugging

    5) The man pages are your friends.

    6) Unless absolutely necessary, scripting with csh family shells should be avoided in favor of Bourne shell family shells. Most people do not use them, and there are many technical drawbacks and flaws in the csh family for scripting.

    7) Phrases like ... or they have no clue are often answered with thunderous silence.

    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  4. #4
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    If you choose to use the cshell for scripting you deserve all the grief you're so obviously having (but don't take my word for it, read an expert on the subject and csh hasn't improved since 1995 when that article was written). Use ksh or bash and regain your sanity!

  5. #5
    Just Joined!
    Join Date
    May 2008
    Posts
    14
    Ok, so thanks to the recommendations of a couple people here I switched over to bash. I *think* my syntax is correct but I am having a problem with a case statement.

    #!/bin/bash
    #
    # name
    #
    # chkconfig: - ## ##
    # description:


    if [ -n $1 ]; then
    QM=TEST
    else
    QM=$2
    fi
    echo $QM

    case "$QM" in
    create)
    my_create_commands
    ;;
    start)
    my_start_commands
    ;;
    stop)
    my_stop_commands
    ;;
    status)
    my_status_commands
    ;;
    restart)
    my_restart_commands
    ;;
    *)
    echo "Usage: $0 {create|start|stop|status|restart}"
    exit 1
    esac

    exit 0

    so if I run this script 'name.sh', ./name.sh start or stop etc always results in usage. Am I missing something?

  6. #6
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    Good decision on switching to Bourne shell family, and you are obviously a quick study to get this done so quickly. Your script is very close.

    Here is a slight re-casting of your script for what I thought you were trying to do (on my file "user3"):
    Code:
    #!/bin/bash
    #
    # name
    #
    # chkconfig: - ## ##
    # description:
    
    
    # if [ -n "$1" ]; then
    if [ -z "$1" ]; then
      QM=TEST
    else
    #  QM=$2
      QM=$1
    fi
    
    # echo $QM
    echo " QM = :$QM:"
    
    case "$QM" in
           create)
               echo my_create_commands
           ;;
           start)
               echo my_start_commands
           ;;
           stop)
               echo my_stop_commands
           ;;
           status)
                echo my_status_commands
           ;;
           restart)
               echo my_restart_commands
           ;;
           *)
                echo "Usage: $0 {create|start|stop|status|restart}"
                exit 1
    esac
    
    exit 0
    Producing:
    Code:
    % ./user3
     QM = :TEST:
    Usage: ./user3 {create|start|stop|status|restart}
    
    % ./user3 start
     QM = :start:
    my_start_commands
    So the questions to ask yourself are why "-z" but not "-n", and why "$1" and not "$2" ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  7. #7
    Just Joined!
    Join Date
    Apr 2008
    Posts
    35
    Hey There,

    Nice conversion to bash on-the-fly

    It looks like your case statement is just missing a ;;

    Code:
    *)
    echo "Usage: $0 {create|start|stop|status|restart}"
    exit 1
    esac
    should be

    Code:
    *)
    echo "Usage: $0 {create|start|stop|status|restart}"
    exit 1
    ;;
    esac

    Cheers,

    Mike

  8. #8
    Just Joined!
    Join Date
    May 2008
    Posts
    14
    Thanks for the help, your changes were correct for the if statement. However I added ;; to the end of the case statement and the script still results in "usage" for every option.

    EDIT: Found my problem, was using the wrong parameter for the switch. Thanks for the help.

    Code:
    #!/bin/bash
    #
    # name
    #
    # chkconfig: - ## ##
    # description: 
    
    
    if [ -z $2 ]; then
      QM=TEST
    else
      QM=$2
    fi
    echo $QM
    
    #case "$QM" in
    case "$1" in 
           create)
               my_create_commands
           ;;
           start)
               my_start_commands
           ;;
           stop)
               my_stop_commands
           ;;
           status)
                my_status_commands
           ;;
           restart)
               my_restart_commands
           ;;
           *)
                echo "Usage: $0 {create|start|stop|status|restart}"
                exit 1
           ;;
    esac
    
    exit 0

  9. #9
    Just Joined!
    Join Date
    May 2008
    Posts
    14
    Maybe you guys can help with one of the commands as well.

    Code:
    while [ -z $temp]
    do
        set temp=$(dspmq | grep Ended)
        sleep 3
        echo "$temp"
    done
    dspmq is a command that contains the string 'Ended' when complete.

  10. #10
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    Generally a new thread is preferred for a new topic.

    Is there a question here? What do you expect, what did you get?

    Is set the same thing in csh and bash? ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...