Multiple File Copy

Unanswered Question
Apr 20th, 2007
User Badges:

I am trying to copy multiple files from flash to a usb key. The issue isn't the media, its the proper command (if one exists). Is it possible to copy multiple files using one statment? For example:


copy flash: usbflash1:


It errors out and doesn't seem to like it.


If not possible natively, does anyone have a TCL script that can do this?


I am trying to come up with a solution to "image" a 2811 running CME (lots of config files, phone loads, etc.) by copying the flash onto a usb key.


Any advice would be appreciated.


Thanks,


Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 5 (2 ratings)
Loading.
Joe Clarke Fri, 04/20/2007 - 08:32
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

See this thread where I gave a sample TCL script to iterate over all files:


http://forum.cisco.com/eforum/servlet/NetProf?page=netprof&forum=Network%20Infrastructure&topic=Network%20Management&CommCmd=MB%3Fcmd%3Dpass_through%26location%3Doutline%40%5E1%40%40.1ddcef70/2#selected_message


You can modify the code to perform a copy operation instead of just printing the file names out. For example:


set fileList [glob -directory flash: -nocomplain *]

foreach file $fileList {

copy flash:/$file usbflash1:/$file

}

Joe Clarke Fri, 04/20/2007 - 08:39
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

Actually, try:


set fileList [glob -directory flash: -nocomplain *]

foreach file $fileList {

copy $file usbflash1:

}


You may also want to set "file prompt quiet" in the config first so that you're not prompted for each response.

mlitka Fri, 04/20/2007 - 09:43
User Badges:

WOW. Worked like a charm. Thanks for that quick solution!!

mlitka Mon, 04/23/2007 - 12:16
User Badges:

How do you include subdirectories and the files they contain?

Joe Clarke Mon, 04/23/2007 - 12:20
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

You'll have to recurse by testing to see what type of file object you've encountered. So you'll need to test each object returned by glob with "file isdirectory". For each object that is a directory, you will need to perform the same glob operation on it.

mlitka Mon, 04/23/2007 - 12:21
User Badges:

OK. Now to tackle that :). An example would be awesome. :>

Joe Clarke Mon, 04/23/2007 - 13:07
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

This is untested, but something like:


proc copyDir { dir dest } {

set fileList [glob -directory $dir -nocomplain *]

foreach file $fileList {

if { [file isdirectory $file] } {

copyDir $file $dest

} else {

copy $file $dest

}

}

}


copyDir flash: usbflash1:

mlitka Mon, 05/07/2007 - 13:26
User Badges:

Thanks. Tried to run this but nothing happened.

Joe Clarke Mon, 05/07/2007 - 13:31
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

The key is the last line:


copyDir flash: usbflash1:



That sets thing in motion. The copyDir proc is just a function. If you don't execute it, nothing will happen. In the above example, "flash:" is the source and "usbflash1:" is the destination.

cablexpress Fri, 10/05/2007 - 08:24
User Badges:

I found this post and had the exact same question. I copied the following to a notepad

set fileList [glob -directory flash: -nocomplain *]

foreach file $fileList {

copy $file usbflash1:

}

saved it as copy_files.tcl

Then TFTP to internal flash of router

I went into CLI and added the following

event manager applet copy_files

event none


then I trigger manually with event manager run copy_files

it says it's triggered but I must be doing something incorrectly.

Joe Clarke Fri, 10/05/2007 - 09:17
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

This is not an EEM policy, but a tclsh script. You need to run it using tclsh from exec mode:


tclsh flash:/copy_files.tcl

Actions

This Discussion