Scripting the Login Banner
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2014 08:23 AM
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
- Labels:
-
Network Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2014 06:31 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2016 03:44 PM
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
