LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-11-2008, 07:45 AM   #1
mou5e
LQ Newbie
 
Registered: Feb 2007
Distribution: Debian Lenny
Posts: 20

Rep: Reputation: 0
Script for switch config generation


Hi

i am trying to generate a whole switch config and paste it directly on the telnet console

Everything is well except vlans

What i am trying to do is tag 8 vlans per one port

11 port + uplink

I give the script the range of 88 vlans and I want the script to pass every 8 vlans on one port beginning from 1 to 11

Here is the script but it does not change the port

#!/bin/sh
x=8
# Enter configure mode
echo configure

# Generate the vlan ids
for vlan in `seq $1 $2`
do

if [ "$x" = "0" ]
then
x=$(($x-1))
fi


echo vlan $vlan # enter vlan mode
echo fixed $x,12 # tag on port and uplink(12)
echo exit # exit from vlan mode

done
 
Old 04-12-2008, 02:25 AM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
You are not changing the value of $x it will always be 8

Therefore the command being passed are:
Code:
configure
vlan 1
fixed 8,12
exit
vlan 2
fixed 8,12
exit
vlan 3
fixed 8,12
exit
vlan 4
fixed 8,12
exit
Is this what you are intending?
 
Old 04-14-2008, 01:48 AM   #3
mou5e
LQ Newbie
 
Registered: Feb 2007
Distribution: Debian Lenny
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Disillusionist View Post
You are not changing the value of $x it will always be 8

Therefore the command being passed are:
Code:
configure
vlan 1
fixed 8,12
exit
vlan 2
fixed 8,12
exit
vlan 3
fixed 8,12
exit
vlan 4
fixed 8,12
exit
Is this what you are intending?
I am intending that after 8 vlans to change port (fixed 8,12) to become (fixed 9,12)

vlan 1
fixed 1,12
exit
vlan 2
fixed 1,12
exit
...........
vlan 8
fixed 1,12
exit
vlan 9
fixed 2,12
exit
......
vlan 16
fixed 2,12
exit
vlan 17
fixed 3,12
exit
 
Old 05-10-2008, 12:38 AM   #4
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
sorry for the delay in posting, I missed the email notification amongst my spam.

Code:
#!/bin/bash

###
### Initialise variables
###
x=1 
last_x=11

vlan_start=1
vlan_set=8

vlan_end=$(($vlan_start + $vlan_set - 1))

echo "configure"
while [ $x -le $last_x ]
do
   for vlan in `seq $vlan_start $vlan_end`
   do
      echo "vlan $vlan"
      echo "fixed $x,12"
      echo "exit"
   done

   x=$(($x + 1))
   vlan_start=$(($vlan_end + 1))
   vlan_end=$(($vlan_start + $vlan_set - 1))
done
I believe this prints the statements that you wanted
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i switch users in a shell script? koobi Programming 8 01-05-2008 02:19 PM
script controlled KVM switch? monkeybus Linux - General 3 09-14-2006 03:49 AM
is there a script that controls what happens when you switch a terminal? Fascistchicken Linux - General 2 09-29-2004 10:11 PM
Is it possible to switch lirc modes with a script? cmisip Linux - Software 0 05-31-2003 12:40 PM
switch users within a script kilobravo Linux - General 4 01-14-2003 03:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration