Очень простой скрипт, позволяющий выполнить несколько команд над списком коммутаторов\маршрутизаторов Cisco
Файл с набором команд — configure_cisco.sh. Его необходимо сделать исполняемым. В нем указываем команды (в данном примере до 16), которые будем выполнять.
~/configure_cis
1 2 3 4 5 6 7 8 9 10 11 12 |
#!/bin/bash file="/root/cisco_list" while read line do # display $line or do somthing with $line echo "$line" /root/send_command.sh $line "conf t" "service timestamps debug datetime localtime" "service timestamps log datetime localtime" "archive" "log config" "logging enable" "logging persistent reload" "hidekeys" "do wr" done < $file |
co.sh
1 2 3 4 5 6 7 8 9 10 |
#!/bin/bash file="/root/cisco_list" while read line do # display $line or do somthing with $line echo "$line" /root/send_command.sh $line "conf t" "service timestamps debug datetime localtime" "service timestamps log datetime localtime" "archive" "log config" "logging enable" "logging persistent reload" "hidekeys" "do wr" done < $file |
Список устройств. Перечисляем IP адреса.
~/cisco_list
1 2 3 4 5 6 7 8 9 10 11 12 13 |
10.10.12.1 10.10.12.2 10.10.12.3 10.10.12.4 10.10.12.6 10.10.12.7 10.10.25.3 10.10.56.1 10.10.56.2 10.10.56.3 10.10.56.4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
#!/usr/bin/expect set ip [lindex $argv 0] set command1 [lindex $argv 1] set command2 [lindex $argv 2] set command3 [lindex $argv 3] set command4 [lindex $argv 4] set command5 [lindex $argv 5] set command6 [lindex $argv 6] set command7 [lindex $argv 7] set command8 [lindex $argv 8] set command9 [lindex $argv 9] set command10 [lindex $argv 10] set command11 [lindex $argv 11] set command12 [lindex $argv 12] set command13 [lindex $argv 13] set command14 [lindex $argv 14] set command15 [lindex $argv 15] set command16 [lindex $argv 16] set user USERNAME set password PASSWORD set password_en ENABLE_PASSWORD spawn telnet $ip expect "Username:" send "$user\r" expect "Password:" send "$password\r" expect ">\r" send "en\r" expect "Password:" send "$password_en\r" expect "#" send "$command1\r" expect "#" send "$command2\r" expect "#" send "$command3\r" expect "#" send "$command4\r" expect "#" send "$command5\r" expect "#" send "$command6\r" expect "#" send "$command7\r" expect "#" send "$command8\r" expect "#" send "$command9\r" expect "#" send "$command10\r" expect "#" send "$command11\r" expect "#" send "$command12\r" expect "#" send "$command13\r" expect "#" send "$command14\r" expect "#" send "$command15\r" expect "#" send "$command16\r" expect "#" send "exit\r" expect "#" send "exit\r" expect "#" send "exit\r" expect "#" send "exit\r" expect "#" send "exit\r" expect "#" send "exit\r" expect "#" send "exit\r" |