cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2653
Views
9
Helpful
4
Replies

Appending to a file in flash using TCL on 2651XM

donlerche
Level 1
Level 1

Wrote a TCL script to save the output from a show command into flash every 1 min (so I could monitor the noise on an ADSL connection). I open the file with an "a" for append option, write the output, then close. Tested on a 2811 and worked a treat with each output appending an entry to the file, but when I tried on a 2651XM, each entry appears to overwrite, so there is only ever the last entry in the file. Anyone any ideas how I can append to a flash file on 2651XM correctly? The IOS is c2600-advsecurityk9-mz.124-15.T7.bin

1 Accepted Solution

Accepted Solutions

This is why I advocated the temp file. Essentially, in pseudo-code:

set fd [open "file" "r"]

set contents [read $fd]

close $fd

set out [open "temp" "w"]

puts $out $contents

puts $out $newcontents

close $out

exec "del /force file"

exec "copy temp file"

exec "del /force temp"

exec "squeeze flash:"

View solution in original post

4 Replies 4

Joe Clarke
Cisco Employee
Cisco Employee

Unfortunately, this is not possible. The built-in flash on the 2651XM does not support random writes. You can see this for yourself with:

show ver | append flash:ver

You'll get:

% Appending is not supported in this file system

But all hope is not lost. You just need to do more work. First, open the existing file for reading, then write out its contents plus the new contents to a temp file. Then, close the open read and write handles, and move the temp file to the desired file on flash.

Joe,

Many thanks for that info.

Had already considered more or less what you propose as a solution if appending was going to be a no-no, however I was just going to open the file in rw mode, read the current contents of the file, append the new line then write back. Is there a reason for you advocating using a temp file? I assume this would still have to be in flash?

The other concern I had was that even though I appear to be re-writing the same file, the free space in flash was getting smaller. A "dir /all" shows that the old version of the file was still there on flash but no longer accessable yet taking up space. My worry is if I keep appending to a file then writing it back, and the original remains there taking up space, then I'm quickly going to run out of flash unless there is some way of getting rid of the "old" copies.

Any further advice would be appreciated.

Don

This is why I advocated the temp file. Essentially, in pseudo-code:

set fd [open "file" "r"]

set contents [read $fd]

close $fd

set out [open "temp" "w"]

puts $out $contents

puts $out $newcontents

close $out

exec "del /force file"

exec "copy temp file"

exec "del /force temp"

exec "squeeze flash:"

Thanks Joe,

Just tried the squeeze and got all the space back although it does take a little time to execute. May have to lower the frequency of the kron process (curently 1 min) that kicks off the tcl script, just to be absolutly sure previous run has completed.

Don

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: