trying to telnet to a device, list the files, and delete them. I can get the script to telnet and log in OK, and even issue the command to list out the files. I can't figure out how to parse the expect_out(buffer) and extract the file name for use in the delete command.
the files list out like this:
dot15# show file contents config
file contents config
number-of-files 13
total-size 308200
FILENAME FOLDERNAME SIZE LAST MODIFICATION TIME
---------------------------------------------------------------------------------
startup-config.xml config 21042 Fri Oct 31 08:38:58 2014
startup-config.20141031.083858.xml config 21262 Fri Oct 31 08:38:09 2014
startup-config.20141031.083809.xml config 20652 Fri Oct 31 03:31:26 2014
startup-config.20141031.033126.xml config 20466 Thu Oct 30 16:15:33 2014
startup-config.20141030.161533.xml config 8895 Thu Oct 30 16:02:23 2014
startup-config.20141030.033124.xml config 28211 Wed Oct 29 03:31:22 2014
startup-config.20141029.033122.xml config 28211 Tue Oct 28 03:31:20 2014
startup-config.20141028.033120.xml config 28211 Mon Oct 27 03:31:18 2014
startup-config.20141027.033118.xml config 28211 Sun Oct 26 03:31:16 2014
startup-config.20141026.033116.xml config 28211 Sat Oct 25 03:31:14 2014
startup-config.20141025.033114.xml config 28211 Fri Oct 24 14:51:18 2014
running-config.restore.xml config 28418 Tue Oct 21 15:56:39 2014
startup-config_dhcp_520.xml config 18199 Thu Jul 31 12:51:53 2014
dot15# exit
I need to include the xml file name in the command to delete the file. Additionally, I need to issue a discrete command to delete the files one-at-a-time (the device does not support wild cards - can simply send delete *.xml)
my script thus far:
#!/usr/bin/expect -f
set ip "10.199.10."
set arg1 [lindex $argv 0]
append ip $arg1
#
# telnet to E5@ ip=arg1
spawn telnet $ip
set timeout 5
#login
expect "login:" { send "sysadmin\n" }
expect "word:" { send "sysadmin\n" }
set timeout 2
#
# list the config files
expect "#" {send "show file contents config\n"}
#
# delete files
(this is the missing puzzle piece)
send "exit\n"
expect EOF
I pass the last octet of the IP in as an argument as I run the script
thanks, in advance.