1

I wrote a basic Cisco expect script. After ssh connection, I want to detect Cisco error output when I send a command line from a file, for example:

SPAIN#sow crypto isakmp sa
       ^
% Invalid input detected at '^' marker.

I want to catch "% Invalid", in my loop and stop the programm.

foreach line $data {
    expect "*#"
    send "$line\r"
    expect {
        "% Invalid*" { send_user "\n Command [ $line ] Failed. \n"; exit 252 }
    }

I get these errors in the output:

SPAIN>enable
Password:
SPAIN#sow crypto isakmp sa
   ^
% Invalid input detected at '^' marker.

SPAIN#invalid command name "sow crypto isakmp sa"
while executing
"$line "
invoked from within
"expect {
     "% Invalid*" { send_user "\n Command [ $line ]  Failed. \n"; exit 252}
}"
("foreach" body line 4)
invoked from within
"foreach line $data {
    expect "*#"
    send "$line\r"
    expect {
        "% Invalid*" { send_user "\n Command [ $line ] Failed. \n"; exit 252}
    }
}"

thanks

1 Answer 1

1

The problem is that [] has a special meaning in Tcl; to execute a command and return the result.

Change this:

expect {
    "% Invalid*" { send_user "\n Command [ $line ] Failed. \n"; exit 252 }
}

To:

expect {
    "% Invalid*" { send_user "\n Command \[ $line \] Failed. \n"; exit 252 }
}

See Evaluation & Substitutions 3: Grouping arguments with [] in the Tcl manual for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.