At my place of work we have to use SSH via CMD to access our Cisco switches. I'd like to write a batch file to semi-automate the login process so that all we need to do is type in the desired switch name and our password. We can't use PUTTY, Cisco Analyser, SSH keys, expect etc., our only allowed method is CMD (it's baffled us too!)
I'm currently the only one of us around and my knowledge on this is not up to par for the job, hence asking you fine folks for a bit of help!
What I'd like the script to do is firstly ask which switch I would like to connect to, use that as a variable to fill in the command at which point the switch will ask for the password to validate access.
The base command for the connection is:
ssh <account-name>@<switch-name(FQDN)>
So far my script reads as:
@echo off
title SSH Switch Access
echo Please enter destination switch name...
As I said, I'm relatively new to writing scripts as I hail from a hardware background so never really had to use them much or had others around that could do it, as much as I'd like to learn how to do this on my own there's a hell of a lot to learn and it'll take me a long while to get conversant enough to do it alone.
Here is one example. You can list the devices as comma separated values in a variable. Simply run a for loop through them and use the
choicecommand to assign a number to hostname. You simply press the keyboard number to make the connection.Because only 9 numeric values can be used (unless you use non numerical) I simply created a next function where you can use option 9 to show the next set. You can use a similar approach to add a previous, if you'd like. Simply update your device list and username.
Note, if you have a huge list of devices, you can either add the devices to a file and read from the file. Again, this might mean a lot of skipping pages to find your device, in that case, it is much simpler to just run the below and type the switch name on request:
Edit: Do not name your script the same as any executable in path. i.e. in this instance, do not name it
ssh.batorssh.cmd.Reason for this being;
cmd.exewill always first check if the basename you supplied is available in the current directory, if not, will it seatch your%path%variable for the basename and extentions in order as specified by%pathext%I this case,
ssh.batorssh.cmdexists in the current directory. When you paunch the script will it then runssh.bat user@switchinstead. Rename your script tomy_ssh.bator similar and also change thesshin the script tossh.exeto ensure the script does not launch itself.