Hey all. I'm writing a script to automatically login to a router, change directories to where crashfiles are located, then listing all files in that directory. This is where I'm at so far and wish to have some user interaction to choose the files.
What I am trying to do is list the files and get the user to choose which files to be copied over to the FTP server including a file name change which will also include adding a case number to the beginning of the file to be copied as part of the file name change sequence.
List files
Ask users which files to be copied
Ask user for case number(enter case number and append to front of original file name. This will not be changing the name on the current server but changing the file name during the copying process.)
And then copy ALL files chosen over to the FTP server with the new file name.
What is the best way to do this?
This is what I got so far.
expect "#"
send "cd /md\r"
expect "#"
send "dir\r"
set files ""
expect {
-re "(\[^\n]+)\n" {
set line [ string trim $expect_out(1,string) ]
if { [llength $line ] > 7 } {
send_user "Hey I found a file its called : [ lindex $line 8 ]\n"
lappend files [ lindex $line 8 ]
}
exp_continue
}
"#" {}
}
foreach f $files {
send_user "$f\n"
}
interact
and the output when I run script is as follows
[local]#cd /md
Current directory is now /md
[local]#dir
Contents of /md/
total 150372
drwxrwxrwx 2 root 0 512 Jun 28 21:52 issu
-rw-r--r-- 1 root 0 1048444 Jun 5 17:02 loggd_ddbg.bin
-rw-r--r-- 1 root 0 1048444 Jun 5 17:02 loggd_dlog.bin
-rw-r--r-- 1 root 0 57773225 Jun 5 17:02 rdb_crash.out
-rw-r--r-- 1 root 0 234581 Aug 19 20:49 file.cfg
-rw-r--r-- 1 root 0 16777216 Jun 28 21:52 rtdb.sav
[local]#Hey I found a file its called : issu
Hey I found a file its called : loggd_ddbg.bin
Hey I found a file its called : loggd_dlog.bin
Hey I found a file its called : rdb_crash.out
Hey I found a file its called : file.cfg
Hey I found a file its called : rtdb.sav
issu
loggd_ddbg.bin
loggd_dlog.bin
rdb_crash.out
file.cfg
rtdb.sav
[local]#