# batch switch config



## arknaz (Feb 12, 2009)

Hey im trying to write this batch file which will allow imput and create a new txt file so the user can copy that and paste it directly into the switches config.



What i have so far that works is but it is rather annoying to have to find new set /p (names) to use. If i use name, or %name% for whatever the user enters, it will appear for the next one as well. So far it is all good as i switch it from %name% %userimp% %input% etc.
Is there a way to remove the last %name% that was typed so it will not appear again? or clear it out?

Also at the end of it (not the end of the code, left a lot out, is there a way for entering the ip address say, 192.168.1.1 255.255.255.0 to make it work? batch files dont like spaces and i cant get the "quotes to include everything typed"

Pretty much copy paste that into a bat file and test it if someone smarter can do. I just want to finish this, then also make a router config.


```
[B]@echo off
echo > Switch.txt
echo >>Switch.txt en
echo >>Switch.txt config t
echo >>Switch.txt line consol 0
echo Create a consol 0 password?
set input=
set /p input=y or n:
if %input%==y goto conpass
if %input%==n goto noconpass
cls
:conpass
Echo Enter Password for consol 0
Echo Spaces do not work yet..
set input= 
set /p userinp=New Password:%userinp%
if %userinp%=="%userinp%" goto con0pass
:con0pass
Echo >> Switch.txt password %userinp%
pause
cls
echo >>Switch.txt login
:noconpass
echo >>Switch.txt logging sync
echo >>Switch.txt exit
echo Create a vty 0 15 password?
set input=
set /p input=y or n:
if %input%==y goto vtypass
if %input%==n goto novtypass
cls
:vtypass
echo >>Switch.txt line vty 0 15
cls
Echo Enter Password for vty 0 15
set input= 
set /p name=New Password:%name%
Echo >> Switch.txt password %name%
cls
echo >>Switch.txt login
echo >>Switch.txt exit
echo >>Switch.txt config t
:novtypass
echo >>Switch.txt no ip domain-lookup
cls
echo Create a Hostname?
set input=
set /p input=y or n:
if %input%==y goto hostname
if %input%==n goto nohost
cls
:hostname
Echo Enter Hostname for Switch 1
set input= 
set /p input=hostname:%input%
Echo >> Switch.txt hostname %input%
:nohost
cls
echo Create a management vlan?
set input=
set /p input=y or n:
if %input%==y goto start
if %input%==n goto endit
cls
:endit
Echo Basic config has been generated...
goto rest
pause
:start
cls
echo What vlan number do you want??
set input=
set /p choice=2-999: %choice%
if %choice%==%choice% goto vlan1
:vlan1
Echo >> Switch.txt vlan %choice%
cls
echo Create a ip address for vlan %choice%
set input=
set /p input=y or n:
if %input%==y goto vlanip
if %input%==n goto rest
cls
:vlanip
Echo Enter ip for vlan %choice%
Echo Spaces do not work yet..
set input= [/B]
set /p userinput=Ip and subnet mask:%userinput%
if %userinput%=="%userinput%" goto test11
:test11
Echo >> Switch.txt ip address "%userinput%"
pause
goto rest
:rest
```
The code so far comes out like and it stops at the ip address due to having a space between the ip and subnet mask.

```
en
 config t
 line consol 0
 password cisco
 login
 logging sync
 exit
 line vty 0 15
 password classsssssdads
 login
 exit
 config t
 no ip domain-lookup
 hostname hkfkfd
 vlan 44
```
Thanks for the help  sorry its so long


----------



## arknaz (Feb 12, 2009)

Also see how i am using 
set /p userinp
set /p name
set /p input
set /p userinput
set /p choice
and so forth? is there a listing of how many you can use? or can i make them up like,
set /p inputipaddress== xxxx?


----------



## Squashman (Apr 14, 2005)

arknaz said:


> Also see how i am using
> set /p userinp
> set /p name
> set /p input
> ...


There probably is some limitation as to how many variables you can assign but it really doesn't matter what you use for a variable name as long as you aren't using some reserved word or command. I wouldn't use choice as a variable because on some versions of CMD shell choice is a cmd. I will take a look at your batch file when I get some extra time and see what I can do for you. I am not quite sure what your problem is.


----------



## Squashman (Apr 14, 2005)

I am kind of confused on why you are doing all your echo redirection to your switch.txt file like that. It doesn't make any sense to me. I have no problems with user input having spaces on any batch files I create.
If I just do something simple like this.

```
@echo off
set /p userin=Please enter Ip Address and Gateway:
echo %userin% > ipinfo.txt
```
It works just fine. I put 192.168.1.100 192.168.1.1 as my input and it echoed it just fine to my text file.


----------

