There is always the option to edit a file locally on your computer in notepad++ and then upload it to Cisco device.
With this trick, you can write or edit a file from Flash memory directly from Cisco IOS console. If you need it for whatever reason, maybe to change something in the config file or something else, this is the way to do it.
I was using if for my next article lab where I needed a file on the flash with at least 1600 bytes so I can pull it from neighbouring router with HTTP and check some details in new TCP connection. It was faster to just create the file directly on the router flash and not creating it on my laptop and then transferring it with FTP or TFTP.
I used Cisco IOS Tcl shell which is available on Cisco devices to allow running Tcl scripts and commands directly from the Cisco IOS CLI prompt. I think that this is the only way of changing text files from Cisco console, correct me in the comments if you know of something else.
Next example will create a text file named test.txt, put some words inside and save the file on Cisco device flash.
R2#tclsh R2(tcl)#puts [open "flash:test.txt" w+] { +>(tcl)#With this trick, you can write or edit a file +>(tcl)#from Flash memory directly from Cisco IOS console. +>(tcl)#} R2(tcl)#tclquit
Or just copy-paste the stuff below when in Privileged EXEC mode:
tclsh puts [open "flash:test.txt" w+] { With this trick, you can write or edit a file from Flash memory directly from Cisco IOS console. } tclquit
We then check if the new file is in the flash:
R2#dir flash: Directory of flash0:/ 1 drw- 0 Jan 30 2013 00:00:00 +00:00 boot 264 drw- 0 Oct 14 2013 00:00:00 +00:00 config 267 -rw- 126335008 Mar 21 2014 00:00:00 +00:00 vios-adventerprisek9-m 270 -rw- 524288 May 6 2014 21:55:20 +00:00 nvram 271 -rw- 199 Feb 28 2018 14:43:40 +00:00 e1000_bia.txt 272 -rw- 100 Mar 1 2018 09:20:50 +00:00 test.txt 2142715904 bytes total (2011242496 bytes free)
And we can even use more command to read the content of the file on the console:
R2#more test.txt With this trick, you can write or edit a file from Flash memory directly from Cisco IOS console. R2#
Nice!
I’m interested in using this method to get a license file made to a cisco router, but when I tried it on a c2900 series, it was giving me issues saying that there were too many characters (more then 256). So then I tried splitting it into acceptable lines, but that didn’t seem to work either, it said the license file was invalid. Any thoughts?
lics use xml format…. just add a carriage return after closed tags
Thanks for the reply! Pardon me if this is a dumb question, but are you just simply saying to start a new line after every occasional ? So it would look something like this?:
tclsh
puts [ open “filename” w+ ] {
blablablablablablablablablablablablablablabla
blablablablablablablablablabla
blablablablablablablablablablablablablablablablablablablabla
blablablablablablablablablabla
blablablablablablablablablablablablablablablablablablablabla
blablablablablablablablablabla
blablablablablablablablablablablablablablablablablablablablablablablablabla
blablablablablablablablablabla
}
tclquit
Sorry my previous comment didn’t display itself the way I wanted. I meant to say [data] and [/data] only substituting [ ] for /
tclsh
puts [ open “filename” w+ ] {
[data]blablablablabla[/data][data]blablablablabla[/data][data]blablablablabla[/data]
[data]blablablablabla[/data][data]blablablablabla[/data]
[data]blablablablabla[/data][data]blablablablabla[/data][data]blablablablabla[/data][data]blablablablabla[/data]
[data]blablablablabla[/data][data]blablablablabla[/data]
[data]blablablablabla[/data][data]blablablablabla[/data][data]blablablablabla[/data][data]blablablablabla[/data]
[data]blablablablabla[/data][data]blablablablabla[/data]
[data]blablablablabla[/data][data]blablablablabla[/data][data]blablablablabla[/data][data]blablablablabla[/data][data]blablablablabla[/data]
[data]blablablablabla[/data][data]blablablablabla[/data]
}
tclquit
Hello,
can you tell me how i do edit on file on flash memory.i did use tclsh to copy file put i could’t do edit
Thanks
I am in the same case as Dave.
I tried to put the license data on several lines but it did not work.
Can I create a single line file entering multiple lines?
I was able to create the license file by using multiple lines using this method.
You need to do ‘exactly’ what Ecze told you what to do. Break the reservation file into lines after ending tags only and nowhere else. Otherwise cisco won’t parse the contents correctly.