Skip to content

Instantly share code, notes, and snippets.

@jezman
Created December 10, 2019 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jezman/e32ea494736370d50fd8015365dbecbf to your computer and use it in GitHub Desktop.
Save jezman/e32ea494736370d50fd8015365dbecbf to your computer and use it in GitHub Desktop.
Dlink switch backup. 1210 and 1510 series.
#!/usr/bin/expect
#==============
# 1510 series =
#==============
set switch "DGS-1510-52"
set ip "switch_ip"
set tftp_host "remote_tftp_server"
set password "pass"
set command "copy running-config tftp: "
set prompt "Switch#"
spawn ssh admin@$ip
set timeout 3
expect {
yes { send -- yes\r }
password: { send -- $password\r }
}
expect -exact $prompt
send "$command\r"
expect host
send "$tftp_host\r"
expect filename:
send "config-$switch-$ip.bin\r"
expect -exact $prompt
send logout\r
#==============
# 1210 series =
#==============
set switch "DGS-1210-10"
set ip "switch_ip"
set tftp_host "remote_tftp_server"
set password "pass"
set command "upload cfg_toTFTP $tftp_host config-$switch-$ip.bin"
set prompt "$switch>"
spawn ssh admin@$ip
set timeout 3
expect {
yes { send -- yes\r }
password: { send -- $password\r }
}
expect -exact $prompt
send "$command\r"
expect -exact $prompt
send logout\r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment