cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2208
Views
5
Helpful
2
Replies

Scripting the Login Banner

Jim Blake
Level 1
Level 1

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 2

Jim Blake
Level 1
Level 1

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

j.rybarczyk
Level 1
Level 1

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

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: