Forum Discussion
dragonflymr
Oct 29, 2015Cirrostratus
Hi,
Below my bash script for manipulating VLAN Enabled on. Probably not perfect one but it's working quite OK for bulk changes 🙂
Be advised, end of lines should be Unix style, so just LF, not CRLF
Specify virtuals to manipulate by virtual name
! /bin/bash
Find by virtual name from $1 (can use RegEx)
Set VLANs and Tunnels to Enabled on using VLAN from $3 based on operation in $2
$2 values:
add Add items to the set
def Reset to the default value - no $3 necessary
del Delete specific items from the set
non Remove all items from the set, no access from any VLAN will be possible - no $3 necessary
rep Replace the set with a new set
Warning: For rep operation previously set VLANS are deleted and
replaced with new VLAN
output=$(tmsh list ltm virtual | grep "ltm virtual" | awk -F" " '{ print $3 }' | grep $1)
for LINE in ${output}; do
echo ${LINE}
case "$2" in
add)
tmsh mod ltm virtual ${LINE} vlans add { $3 } vlans-enabled ;;
def)
tmsh mod ltm virtual ${LINE} vlans default vlans-disabled ;;
del)
tmsh mod ltm virtual ${LINE} vlans delete { $3 }
test=$(tmsh list ltm virtual one-line | grep "vlans {" | awk -F" " '{ print $3 }' | grep $1)
echo $test
if [ "$test" = '' ]; then
echo "Last VLAN deleted"
tmsh mod ltm virtual ${LINE} vlans default vlans-disabled
fi ;;
non)
tmsh mod ltm virtual ${LINE} vlans none ;;
rep)
tmsh mod ltm virtual ${LINE} vlans replace-all-with { $3 } vlans-enabled ;;
esac
done
Specify virtuals by VLAN name currently set as Enabled on
! /bin/bash
Find virtuals with VLAN enbled on specified in $1 set VLAN to value in $3
based on operation in $2
$2 values:
add Add items to the set
def Reset to the default value - no $3 necessary
del Delete specific items from the set
non Remove all items from the set, no access from any VLAN will be possible - no $3 necessary
rep Replace the set with a new set
Warning: For rep operation previously set VLANS are deleted and
replaced with new VLAN
output=$(tmsh list ltm virtual one-line | grep "vlans {.*\ $1\ " | awk '{ print $3 }')
for LINE in ${output}; do
echo ${LINE}
case "$2" in
add)
tmsh mod ltm virtual ${LINE} vlans add { $3 } vlans-enabled ;;
def)
tmsh mod ltm virtual ${LINE} vlans default vlans-disabled ;;
del)
tmsh mod ltm virtual ${LINE} vlans delete { $3 }
test=$(tmsh list ltm virtual ${LINE} one-line | grep "vlans {" | awk -F" " '{ print $3 }')
echo $test
if [ "$test" = '' ]; then
echo "Last VLAN deleted"
tmsh mod ltm virtual ${LINE} vlans default vlans-disabled
fi ;;
non)
tmsh mod ltm virtual ${LINE} vlans none ;;
rep)
tmsh mod ltm virtual ${LINE} vlans replace-all-with { $3 } vlans-enabled ;;
esac
done
Piotr