Question

I created bash script to backup a lot of different switches using expect. Because for example command show config current_config on D-Link switches displays one line after another too slow (like 1-2 lines per second, when there is more that 1000 lines) I decide to enable clipagaing and when switch ask for reaction I use loop like this:

for {} {1} {} {
expect -exact "CTRL" {send -- " "} -exact "DES-3028:" {send -- "logout\r"}}

or send -- "\r" for Enter (one line) instead of space (one page)

When I use that loop backing up one switch takes less than 5 seconds but in output I get lot of lines containing switch questions what to do.

When I open file created by expect in vim I see lines like:

^M ^[[7mCTRL+C^[[0m ^[[7mESC^[[0m ^[[7mq^[[0m Quit \
^[[7mSPACE^[[0m ^[[7mn^[[0m Next Page ^[[7mENTER^[[0m Next Entry \
^[[7ma^[[0m All ^M^@ ^M^@^[[1Aconfig loopdetect port 1 state enabled

When I do cat file1 I get

config loopdetect port 1 state enabled

that's what I want to get

When I do cat file1 > file2 I get exact copy of file1

Here you have example file https://www.dropbox.com/s/wo0usn8cfja7dbo/przyklad

Try to cat it and cat it to another file. I want effect of cat to screen but to another file.

I will be grateful for any advice.

Was it helpful?

Solution

There should be a HTTP page where you can download the whole config as a file.

Use a tool like wget or curl to download the file from a script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top