- to ping multiple devices:
tclsh
foreach ADDRESS {
192.168.1.231
192.168.1.232
192.168.1.233
192.168.1.254
192.168.1.111
} {ping $ADDRESS }
- More advanced script that outputs OK next to the address if it works and unreachable if not. "puts" is like the echo command in linux
tclsh
foreach ADDRESS {
192.168.1.231
192.168.1.232
192.168.1.233
192.168.1.254
192.168.1.111
} {
set RESULT [exec "ping $ADDRESS repeat 5 timeout 1"];
if { [regexp "!!!" $RESULT]} { puts "$ADDRESS OK"} else { puts "$ADDRESS Unreachable"}
}
IOS.sh
# stored in running config
R1(config)# shell processing full
# short term
R1# terminal shell
# This will give us the commands we have access to
R1# man
(( evaluate a numeric test expression
IOS.sh The IOS shell
[[ evaluate a logical test expression
cat output data from a pipe or file to the terminal
compatibility compatibility information on IOS.sh
control control constructs in IOS.sh
cut edit piped output
echo echo arguments to the terminal
expressions usage of expressions in IOS.sh
false return false in while or if expressions, and set the result
fetch return values from the configuration database
for IOS.sh for loops
functions IOS.sh function facility
grep search for regular expressions in piped output or files
head print the first lines in the input
if-else IOS.sh if command
interface print interfaces that match the argument
let evaluate a numeric expression, and set the result
local Declare a variable in local to the function
man print information for builtins
more page piped output to the terminal
nl number the lines in the input
null ignore the input
printf output formatted data to the terminal
quoting IOS.sh quoting facility
read read input into variables
scripting how to script the IOS CLI
set_oper set operational values
sleep pause execution of the terminal
sort sort the input
tail print the tail of the input
true return true in while or if expressions, and set the result
uname print system information
variables usage of variables in IOS.sh
wc count lines, words, and chars
while iterate while an expression is TRUE
# This will set a description on all interfaces
R1# for ii in `interface` ; do
conf t
interface $ii
description "Hello everyone"
end
done
IOS.sh
IOS.sh
IOS.sh