For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

TAB Completion For V9 LTM

Problem this snippet solves:

The author got tired of not being able to TAB complete some b commands in v9, created a bash shell to help speed up the process

The following is example of tab completion:

[root@bigip1:Active] ~ # b v
version    virtual    vlan       vlangroup
[root@bigip1:Active] ~ # b virtual 
address  list     show     vs_http  vs_text
[root@bigip1:Active] ~ # b virtual vs_
vs_http  vs_text
[root@bigip1:Active] ~ # b virtual vs_http _

Create the file called redcomp.sh or whatever you would like to call it, in /etc/profile.d/ and execute the following:

chmod +755 redcomp.sh

this should then run the script when you log in.

Feel free to extend it and improve this code share

Note: This has been tested on v9.4.x branch

Code :

#!/bin/bash
#
# BASH completion for bigpipe on BIGIP 9.4.x
#
# Licensed under the GPL v2
# See http://www.gnu.org/licenses/gpl-2.0.html for full License Text
#
# Author: James Deucker, Red Education Pty Ltd
#
# Version 0.3
# 
_virtual()
{
    case $COMP_CWORD in
        2)
             local list=$(for x in `b virtual show | egrep "^\+-> VIRTUAL" | cut -d " " -f 3` list show address help; do echo ${x} ; done )
             COMPREPLY=( $(compgen -W "${list}" -- ${cur}) )
             return 0
             ;;
        3)
             local list=$(for x in `b help | egrep "^virtual \([^\)]*\) [a-z]" | cut -d " " -f 6 | sort | uniq`; do echo ${x} ; done )
             COMPREPLY=( $(compgen -W "${list}" -- ${cur}) )
             return 0
             ;;
     esac
}

_pool()
{
    case $COMP_CWORD in
        2)
            local list=$(for x in `b pool show | egrep "^POOL" | cut -d " " -f 2` list show; do echo ${x} ; done )
            COMPREPLY=( $(compgen -W "${list}" -- ${cur}) )
            return 0
            ;;
        3)
             local list=$(for x in `b help | egrep "^pool \([^\)]*\) [a-z]" | cut -d " " -f 6 | sort | uniq`; do echo ${x} ; done )
             COMPREPLY=( $(compgen -W "${list}" -- ${cur}) )
             return 0
             ;;
    esac
}

_bp() 
{
    local cur prev opts base
    COMPREPLY=()
    base="${COMP_WORDS[1]}"
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    #
    #  The basic options we'll complete.
    #
    opts=`b help | egrep "^[a-z]" | cut -d " " -f 1 | sort | uniq | xargs`


    #
    #  Complete the arguments to some of the basic commands.
    #
    case "${base}" in
virtual)
            _virtual
            return 0
            ;;
        pool)
            _pool
            return 0
            ;;
        *)
            COMPREPLY=( $(compgen -W "help" -- ${cur}) )
        ;;
    esac

   COMPREPLY=($(compgen -W "${opts}" -- ${cur}))  
   return 0
}
complete -F _bp b bp bigpipe

# Note: This has been tested on v9.3.x branch

#!/bin/bash
#
# BASH completion for bigpipe on BIGIP 9.3.x
#
# Licensed under the GPL v2
# See http://www.gnu.org/licenses/gpl-2.0.html for full License Text
#
# Author: James Deucker, Red Education Pty Ltd
#
# Version 0.3b
# 
_virtual()
{
    case $COMP_CWORD in
        2)
             local list=$(for x in `b virtual show | egrep "^\+-> SERVER" | cut -d " " -f 3` list show address help; do echo ${x} ; done )
             COMPREPLY=( $(compgen -W "${list}" -- ${cur}) )
             return 0
             ;;
        3)
             local list=$(for x in `b help | egrep "^virtual \([^\)]*\) [a-z]" | cut -d " " -f 6 | sort | uniq`; do echo ${x} ; done )
             COMPREPLY=( $(compgen -W "${list}" -- ${cur}) )
             return 0
             ;;
     esac
}

_pool()
{
    case $COMP_CWORD in
        2)
            local list=$(for x in `b pool show | egrep "^POOL" | cut -d " " -f 2` list show; do echo ${x} ; done )
            COMPREPLY=( $(compgen -W "${list}" -- ${cur}) )
            return 0
            ;;
        3)
             local list=$(for x in `b help | egrep "^pool \([^\)]*\) [a-z]" | cut -d " " -f 6 | sort | uniq`; do echo ${x} ; done )
             COMPREPLY=( $(compgen -W "${list}" -- ${cur}) )
             return 0
             ;;
    esac
}

_bp() 
{
    local cur prev opts base
    COMPREPLY=()
    base="${COMP_WORDS[1]}"
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    #
    #  The basic options we'll complete.
    #
    opts=`b help | egrep "^[a-z]" | cut -d " " -f 1 | sort | uniq | xargs`


    #
    #  Complete the arguments to some of the basic commands.
    #
    case "${base}" in
virtual)
            _virtual
            return 0
            ;;
        pool)
            _pool
            return 0
            ;;
        *)
            COMPREPLY=( $(compgen -W "help" -- ${cur}) )
        ;;
    esac

   COMPREPLY=($(compgen -W "${opts}" -- ${cur}))  
   return 0
}
complete -F _bp b bp bigpipe
Published Mar 12, 2015
Version 1.0
No CommentsBe the first to comment