Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

New Member

Scripting the Login Banner

I'm not sure if this question is in the right place, so feel free to advise or move it :)

I'm changing some configurations on a bunch of routers (a LOT) so I've written some expect scripts. Its all kicked off by a script that reads an IP address from a file, and passes it to an expect script that logs on to the router who's address it is, then opens a third file which consists of a series of plain-language IOS commands. The commands are issued to the router and the config is done. Nothing clever here, its been done a few times before. However, I'm trying to write a Login Warning banner. The banner command goes across OK, the first line of the banner goes across, then the script hangs. I *think* its because after each line within the "banner" config, there is an "empty" newline, nothing to trigger the expect script driving the commands, so it sits there waiting for something that never comes.

 

I've tried making the banner command a single line with "\n" separating it into the format I want, that doesn't work. I also tried with 0x0a (ascii newline) but that didn't work either.

 

has anybody done this successfully, and where am I going wrong?

 

Thanks

 

Jim

2 REPLIES
New Member

OK, I fixed it. Expect is

OK, I fixed it. Expect is waiting for the # prompt before it provides the next line. If you end each line of the banner with a #, it works, even though the C/R and # are round the wrong way. It may not be the most tidy programming but it works

New Member

This syntax should work for

This syntax should work for you:

<snip>

send "config terminal\r";
expect "# "

send "banner login $\n";
send "********************************************************************************\n";
send "Here is our new corporate approved login banner.  Bad guys stay away.\n";
send "I'm serious.  We're watching everything you do, so don't even try it.\n";
send "********************************************************************************\n";
send "\n";
send "$\r";
expect "# "

send "end\r";
expect "# "
send "write mem\r";
expect "# "

</snip>

Jamie

275
Views
5
Helpful
2
Replies