Forum Discussion

Pranav_73262's avatar
Pranav_73262
Icon for Nimbostratus rankNimbostratus
Aug 28, 2013

How to disable Virtual Server in LTM using TMSH command?

Hi, we need to accomplish following task using shell script/tmsh in LTM v 11.3 For maintenance purpose, we need a script which will bring down all VSs related to particular client & can bring it up on e maintenance window is over. Script should take client name as input & disble/enable all VS related to that client. Is it possible doing shell/perl script? Which commands I should use for tmsh, also will it support switch statement for looping or checking client name?

 

5 Replies

  • Script should take client name as input & disble/enable all VS related to that client.

     

    how does client name relate to virtual server (i.e. how do you know what virtual server is based on client name)?

     

    • Pranav_73262's avatar
      Pranav_73262
      Icon for Nimbostratus rankNimbostratus
      we will have to do manual mapping of client names with VS. e.g.: switch (Client A) { Disable VS1 Disable VS2 } switch (Client B) { Disable VS3 Disable VS4 } Is it possible to do?
  • Script should take client name as input & disble/enable all VS related to that client.

     

    how does client name relate to virtual server (i.e. how do you know what virtual server is based on client name)?

     

    • Pranav_73262's avatar
      Pranav_73262
      Icon for Nimbostratus rankNimbostratus
      we will have to do manual mapping of client names with VS. e.g.: switch (Client A) { Disable VS1 Disable VS2 } switch (Client B) { Disable VS3 Disable VS4 } Is it possible to do?
  • Here's an idea. Put the client name in the description block of the virtual server definition and use a shell script like this:

    !/bin/bash
    if [ -z "$1" ] || [ -z "$2" ]
    then
        echo "Usage: clientdown.sh [CLIENTNAME] [UP/DOWN]"
    elif [ "$2" != "UP" ] && [ "$2" != "DOWN" ]
    then
        echo "Usage: clientdown.sh [CLIENTNAME] [UP/DOWN]"
    else
        output=$(tmsh list /ltm virtual one-line |grep "description $1" | awk -F" " '{ print $3 }')
    
        if [ -z "${output}" ]
        then
            echo "No client found by that name"
        else
            for LINE in ${output}
            do
                if [ "$2" == "UP" ]
                then
                    echo "Enabling virtual \"${LINE}\" for client $1"
                    tmsh modify /ltm virtual ${LINE} enabled
                elif [ "$2" == "DOWN" ]
                then
                    echo "Disabling virtual \"${LINE}\" for client $1"
                    tmsh modify /ltm virtual ${LINE} disabled
                fi
            done
        fi
    fi
    

    I didn't bother making the command line arguments case-insensitive, so you'd need to have a naming/case convention for your client names (or modify the script). This will search through the VIP list for a given client name in the description field and then enable or disable those.