Professional Documents
Culture Documents
Bash is a Unix shell, which is a command line interface (CLI) for interacting with an operating system
(OS). Any command that you can run from the command line can be used in a bash script. Scripts
are used to run a series of commands.
1. The first step to prepare our script is to create a file with .sh extention
Create <filename>.sh file
For example: “touch change_cfg.sh”
2. Make it executable.
chmod +x filename.sh
#!/bin/bash
In the script itself we have to define a method for authentication. Since our goal is to make the script
log into a lot of devices we don’t want interactively performing password authentication for each
device. So how do we login over ssh without using password less RSA Public keys? How do we login
non-interactively performing password authentication?
Answer: sshpass. With this program we can define separate fine which script will use to get the
password without the need to manually type it each time.
You can see that here we have defined 2 different files under working directory. (hosts and pass). As
you can imagine in those files we define “hosts” on which the script will login and the password
which will be used for authentication (pass file).
The first part of the script is basically performing the checks against the subnet mask value under
VLAN10 interface.
Basically this line says: Do not care for the first part of the output it could be anything (Regular
expression), but pay attention to the subnet mask value (the backward slash is to distinguish the “.”
Because this symbol has another meaning in the code).
Echo “26 bit mask $IP_MASK”<- echo command in linux is used to display line of text/string that are
passed as an argument . In our case this is IP_Mask.
With this echo command script will print the value for the subnet mask found.
#Use the value from IP_MASK but replace pattern 255.255.255.192 with 255.255.255.224
As you might know IP_MASK and NEW_MASK are variables and the values are determined based on
the show sys interface VLAN10 output from each device script will login to.
If script is not able to find suitable mask – different then 255.255.255.192 print “No suitable mask
detected”