FS="switch-nexus-1,switch-nexus-2,switch-nexus-3,switch-nexus-4,switch-catalyst-1,switch-catalyst-2,switch-catalyst-3,switch-catalyst-4,switch-catalyst-7"
HS="switch-nexus-1,switch-nexus-2,switch-nexus-3,switch-nexus-4,switch-catalyst-5"

function doit {
 case $action in
 a)
  if [ "$vname" == "" ]
  then
   cmd="echo conf t\nvlan $vlan\nend\ncopy run start\n\nnexit\n"
  else
   cmd="echo conf t\nvlan $vlan\nname $vname\nend\ncopy run start\n\nexit\n"
  fi
 ;;
 r)
  cmd="echo conf t\nno vlan $vlan\nend\ncopy run start\n\nexit\n"
 ;;
 esac
 $cmd | cmc -n $SW
}


while [ "$action" != "a" ] && [ "$action" != "r" ]
do
 read -p "Add or Remove VLAN [a|r]" action
done

if [ "$action" == "a" ]
then
 read -p "VLAN name:" vname
fi

if [ "$vname" == "" ]
then
 vname="no name"
fi

while [ "$zone" != "f" ] && [ "$zone" != "h" ]
do
 read -p "Finance oder Hosting? [f|h]" zone
done

while [ "$vlok" != "1" ]
do
 read -p "VLAN [1-4094]" vlan
 if [[ $vlan =~ ^[0-9]*$ ]]
 then
  if [ "$vlan" -gt 0 ] && [ "$vlan" -lt 4095 ]
  then
   vlok=1
  else
   echo "VLAN number out of valid range"
  fi
 else
  echo "invalid characters"
 fi
done
echo ""

if [ "$action" == "a" ]
then
 echo -n "add vlan $vlan ($vname) to "
 if [ "$vname" == "no name" ]
 then
  vname=""
 fi
else
 echo -n "remove vlan $vlan from "
fi

case $zone in
f)
 echo "Finance"
 SW=$FS
 doit $SW $action $vlan
;;

h)
 echo "Hosting"
 SW=$HS
 doit $SW $action $vlan
;;

*)
 echo ""
esac

