on 05-May-2015 10:39
Problem this snippet solves:
How to use this snippet:
Usage:script_name pool_name pool_name ...
Remember to use the correct case and full pool names.
Code :
#!/bin/bash Err_NOARGS=75 if [ ! -n "$1" ] then echo "Usage: `basename $0` pool_name pool_name etc..." exit $Err_NOARGS fi for pools in "$@" do echo "Virtual Servers using Pool: $pools" echo for vips in `tmsh list /ltm virtual pool | grep -x -B2 " pool ${pools}" | awk -F" virtual |\{" '{print $2}' 2>/dev/null` do echo " $vips" done echo done
Tested this on version:
11.6Is 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?
Thanks,
@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_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}'