write and edit text files on the cisco router flash

From CCIE networking & linux
Jump to: navigation, search

Have you ever wondered how to create a text file inside Cisco router or switch using linux commands "vim" or "touch"? I am afraid that is not possible. But there is another way...Why would we would like to use it? For example to put some new config files to the flash without using TFTP server. Only via telnet/ssh. Or just to modify config files on the flash and then force router to use new config on the boot process. I am afraid that with "vi"thet is not possible. But there is another way...

The way is with TCL scripting.

SW-TSW-215#sh flash: 
!
Directory of flash:/
   2  -rwx        3096   Mar 4 1993 22:45:38 +01:00  multiple-fs
   3  drwx        1024   Mar 1 1993 01:06:05 +01:00  ies-lanbase-mz.122-55.SE5
 726  -rwx         796   Mar 2 1993 03:17:12 +01:00  vlan.dat
 729  -rwx    10634178   Mar 1 1993 01:29:01 +01:00  ies-lanbasek9-mz.122-58.SE1.bin
 731  -rwx        3568   Mar 4 1993 22:45:38 +01:00  private-config.text

Enter the TCL configuration.

 SW-TSW-215#tclsh
 SW-TSW-215(tcl)#puts [open "flash:test.cfg" w+] {
 +>This is a test config file.
 +>Line 2 bla bla.
 +>Third line yes.
 +>}
 SW-TSW-215(tcl)#tclquit

Now we will check if the file is here.

SW-TSW-215#sh flash: 
Directory of flash:/
   2  -rwx        3096   Mar 4 1993 22:45:38 +01:00  multiple-fs
   3  drwx        1024   Mar 1 1993 01:06:05 +01:00  ies-lanbase-mz.122-55.SE5
 726  -rwx         796   Mar 2 1993 03:17:12 +01:00  vlan.dat
 729  -rwx    10634178   Mar 1 1993 01:29:01 +01:00  ies-lanbasek9-mz.122-58.SE1.bin
 731  -rwx        3568   Mar 4 1993 22:45:38 +01:00  private-config.text
 730  -rwx       10396   Mar 4 1993 22:45:38 +01:00  config.text
 732  -rwx       12254   Mar 4 1993 22:51:33 +01:00  test.cfg

File is here, so now we could use one linux command more to verify the content:

SW-TSW-215#more flash:test.cfg
This is a test config file.
Line 2 bla bla.
Third line yes.

We can make only erase startup-config copy flash:test.cfg start and boot up router with modified configuration. It is like copy-pasting config to the running config, but with this TCL feature we could copy-paste to any file on the flash.


Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox
Offer
Martin Satara