I have a bash script which can login to Cisco switch and shut/noshut any port I have defined in it.
What I want is that I can add variable, like I can define port number in a command like this:
./cisco.sh 10 #10 is the port number
But the script is not letting me add any variable and gives the following error:
can't read "1": no such variable
while executing "set PORT "$1""
Here is the code of the script I am using:
#!/usr/bin/expect -f
set timeout 20
set IPaddress "192.168.0.1"
set Username "zaib"
set Password "zaib"
set PORT "$1"
spawn ssh -o "StrictHostKeyChecking no" $Username@$IPaddress
expect "*assword: "
send "$Password\r"
expect ">"
send "enable\r"
expect "*assword: "
send "$Password\r"
send "conf term\r"
send "interface gigabitEthernet 1/0/$PORT\r"
expect "#"
send "shut\r"
expect "#"
send "exit\r"
expect "#"
send "exit\r"
send "wr\r"
send "exit\r"
exit