05-08-2009 04:22 AM
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
Solved! Go to Solution.
05-08-2009 10:47 AM
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:"
05-08-2009 09:32 AM
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.
05-08-2009 10:40 AM
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
05-08-2009 10:47 AM
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:"
05-08-2009 11:27 AM
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide