顯示具有 expect 標籤的文章。 顯示所有文章
顯示具有 expect 標籤的文章。 顯示所有文章

2013年7月23日 星期二

每日自動備份 Fortigate 設定檔


For v5.0,build0252 (GA Patch 5)
首先在 Fortigate上面建立一個名為backup的使用者,密碼為YourPassword,權限設定如下:





















然後在 Linux 建立 sh 並賦予執行權限和建立排程,檔案內容如下:
(範例中的備份伺服器是使用 tftp)

#!/bin/bash
user="backup"
password="YourPassword"
tftp_ip="YourBackupServerIP"
fg_devices="YourFortigateIP"
date="$(date +"%Y%m%d")"
for fg_device in $fg_devices ; do
  expect -c "
  set timeout 30
  spawn ssh $user@$fg_device
  expect \"(yes/no)\" { send \"yes\r\"; exp_continue }
  expect \"*password:*\"
  set send_slow {1 0.05}
  send -s \"$password\r\"
  send_user \"$password\r\"
  expect \"FG*\"
  send -s \"execute backup full-config tftp $fg_device-$date.cfg $tftp_ip\n\"
  expect \"FG*\"
  send -s \"exit\n\"
  interact"
done


2013年3月5日 星期二

使用 Expect 備份網路設備設定檔 for Extreme


支援 Extreme DB8800系列、X450a系列、X460系列

#!/usr/bin/expect -f

if { $argc != 4 } {
        send_user "usage: extreme.exp device_ip username password server_ip \n"
        exit
}

set timeout 1
set TERM ANSI
set date [exec date +%Y%m%d]

set DEVICE [lindex $argv 0]
set USERNAME [lindex $argv 1]
set PASSWD [lindex $argv 2]
set SERVER [lindex $argv 3]

spawn telnet
expect "telnet> "
send "open $DEVICE\r"
sleep 1
expect "login:"
send "$USERNAME\r"
sleep 1
expect "password:"
send "$PASSWD\r"
sleep 1
expect "#"
send "upload configuration $SERVER $DEVICE-$date vr VR-Default\r"
sleep 3
expect "#"
send "exit\r"
interact

使用 Expect 備份網路設備設定檔 for HP


支援 HP ProCurve Switch 2610系列、2510系列

#!/usr/bin/expect -f

if { $argc != 4 } {
        send_user "usage: hp.exp device_ip username password server_ip \n"
        exit
}

set timeout 1
set TERM ANSI
set date [exec date +%Y%m%d]

set DEVICE [lindex $argv 0]
set USERNAME [lindex $argv 1]
set PASSWD [lindex $argv 2]
set SERVER [lindex $argv 3]


spawn telnet
expect "telnet> "
send "open $DEVICE\r"
sleep 1
expect continue { send "\r" ; exp_continue }
sleep 1
expect "Username:"
send "$USERNAME\r"
sleep 1
expect "Password:"
send "$PASSWD\r"



sleep 1
send "\r\r"
expect "#"
send "copy running-config tftp $SERVER $DEVICE-$date\r"
sleep 1
expect "#"
send "exit\r"
sleep 1
expect ">"
send "exit\r"
sleep 1
expect "Do you want to log out"
send "y\r"
interact