bash script to list which virtual servers are using a specific pool.

Problem this snippet solves:

bash script to list which virtual servers are using a specific pool

How to use this snippet:

Usage:script_name pool_name pool_name ...

Remember to use the correct case and full pool names.

Code :



if [ ! -n "$1" ]
                echo "Usage: `basename $0` pool_name pool_name etc..."
                exit $Err_NOARGS

for pools in "$@"
                echo "Virtual Servers using Pool: $pools"

                for vips in `tmsh list /ltm virtual pool | grep -x -B2 "    pool ${pools}" | awk -F" virtual |\{" '{print $2}' 2>/dev/null`
                                echo "  $vips"

Tested this on version:

Published May 05, 2015
Version 1.0

Was this article helpful?


  • I kinda wrote my own, figured that I would share. This script shows each virtual server associated pool, pool member, and also shows the monitor that is being used by the pool. I call it the vipmapper. Also shows which virtual servers don't have a pool assigned. virtuallist=$(tmsh list ltm virtual | grep virtual | cut -d' ' -f3 | tr "\n" " " ); for v in $virtuallist ; do DEST=""; POOL=""; MEMB=""; DEST=$(tmsh list ltm virtual $v | grep destination | cut -d' ' -f6) POOL=$(tmsh list ltm virtual $v | grep pool | cut -d' ' -f6) MEMB=$(tmsh list ltm pool $POOL | egrep ':|address '| sed '$!N;s/\n/ /') MON=$(tmsh list ltm pool $POOL | grep " monitor") if [ "$POOL" != "" ]; then echo ""; echo " Virtual: $v - $DEST"; echo " Pool: $POOL"- $MON; echo "$MEMB"; else echo ""; echo "!! Virtual $v $DEST has no pool assigned"; echo ""; fi done
  • Is there a way to test if a Virtual server exist. I have a bash script that will look at a seed file, if it the virtual server does not exist, it will list all the virtual servers on the device. I want to use an if then else to test, I tried blank, I tried to use "not found", no luck., Anyone have anything close?




  • @Wallace, assuming your are iterating through a list of VS names and you want to check if they exist first, the following may work. It attempts to list the VS name passed in, if it exists do something, if the command errors ie. the VS doesn't exist do nothing.


    tmsh_out=$(tmsh -q list ltm virtual $vs 2>/dev/null)

    [[ "$tmsh_out"  ]] &&  echo 1

  • Hi,

    I suggest to replace tmsh command with this one

    tmsh list /ltm virtual one-line | grep "pool ${pools}" | awk '{print $3}'