I have an office with about 20 switches about 4 or 5 routers. There is two types of switches, however they are the same brand and so they will use the same commands to remotely configure.
All of the switches and routers are accessible via SSH.
switches and routers are all accessible via SSH
I want a script made that our technicians can run from a linux console.
The script will manages the backup, restore and deployment of routers and switches. Passwords for swithes and routers will all be uniform and will just be set in a variable of the script that we can open and edit if required. We will have already preconfigured the switches, so there is no need for the script to interact with the content of the configs. The script would manage a basic database of switch/router names and IP addresses.
Imagine that the name of the script is "script". Here are some of the example commands that we would run from the linux console.
./script router add <routername> <routerip>
./script switch add <switchname> <switchip>
./script router delete <routername> <routerip>
./script switch delete <switchname> <switchip>
**what this does it just adds a switch or router to the database and gives it a name and IP address
./script switch backup <switchname>
**this would ssh into the ip address of the switch and use commands to output the running config to a file with the name of the switch and a datestamp. if there is an existing file for that date it will just overwrite it.
for example the fill would be switch-<switchname>-config-2016-08-24.conf
./script switch restore <switchname>
**will take the most recent config file for the named switch upload it to the switch and reboot the switch
./script switch restore <switchname> 2016-08-23
**will restore the switch config from that date
**same obviously for ./script router restore <routername> (date)
./script switch deploy <switchname>
**deploy will work as follows:
**we will have several spare switches and routers
**these will all have the same IP and username and password so that the script can write the config to any of them if they are plugged onto the network. We will make sure that all of the spare routers and switches are configured correctly.
i.e. if 192.168.1.254 is the IP of every spare router, and 192.168.1.253 is the IP of every spare switch, and admin / admin as the username and password, if we have a router or switch die we could use the following command to deploy a new version of "router5".
./script router deploy router5
./script router deploy router5 2016-08-23
this will result in ssh to email@example.com and upload the config file router-router5-config-2016-08-23.xml to the router and then reboot the router allowing us to deploy a router quickly from a backup.
we will always have a spare router and spare switch connected to the network at all times. as a result, we would like a function "testdeploy". This will login to the router and test the login to the spare switch and spare router.
When adding or removing a switch to the database it will also manage a script run by cron to do daily backups of all switches and routers, as well as the function above "testdeploy" which would be outputted to an email every day.
all switches are dell switches, which, like cisco we can just write or save the config to and from the switch.
all the routers are pfsense, we can sftp the config file down to backup and to restore, sftp the config up and reboot the server to apply.
we have already built a script that downloads the configs of all of our switches and routers, so you can take a look at this. We just require assistance with tieing it all together in a script with a database that manages the routers and switches, and automatically builds cron jobs to do daily backups of all of the named switches/routers in the database.
./script router makespare router5
./script switch makespare switch10
it could also be used to turn a running production router/switch into a spare, for testing or other reasons, making sure that the device is configured correctly for redeployment
we could have a sparerouter.conf and spareswitch.conf which we can provide so that it can be saved in the working directory so that we can upload these to the device to do this function.