Avaya Support Forums  

Go Back   Avaya Support Forums > Avaya Networking Products

Thread Tools Search this Thread Display Modes
Old 09-13-2011, 04:27 PM
mayler mayler is offline
Hot Shot
Join Date: Jul 2011
Posts: 23
mayler has 10 reputation points
Default Automating SSH Login using Expect

Figured I'd share this with the community. It works for all devices supporting SSH.
Requires expect

Instead of this:
pounding keyboard... ouch ah man, this sucks...everyday all the time, bla
ssh Manager@ip.add.re.ss
enter password, etc.

You'll tab complete devices and automatically login. Use the following script.

Create an executable file in /usr/local/bin/ called router-street-town.city.state (if you name your equipment in DNS, use the name. If not, use your favorite name for the equipment (ie: pos.network - but requires a change to ipaddr "")

#!/usr/bin/expect -f
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg

set ipaddr [exec basename $argv0]
set pword "yourpassword"
set timeout 10
spawn $env(SHELL)
match_max 100000
send -- "ssh -o StrictHostKeyChecking=no Manager@$ipaddr\r"
expect "Manager@$ipaddr's password:" { send "$pword\r" }
expect "*"

exec basename $argv0 is the best part of this. Instead of telling the script to use set ipaddr router-street-town.city.state in the file, you are using the filename instead. This allows you to simply change the filename, or copy the file to a new filename
So I have 100+ devices I have to remote into once and a while, router-street-town.city.state, edge-street-town.city.state, etc. I don't always remember the site name so tab completion works too.
It might actually look like this:

ls *.ntwk

From my command prompt I'd just type:

ETC. Tab completion and direct connect.
Reply With Quote

expect ssh login script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 10:50 PM.

This Forum is provided solely for the use and convenience of Avaya customers and partners. Use of the Forum is subject to the Terms and Use and Privacy Statement found at www.avaya.com. No other use is permitted. The Forum including all content posted is “AS IS” and Avaya expressly disclaims all warranties and/or guarantees as to its accuracy, reliability, usefulness, quality or non-infringement of intellectual property. Avaya reserves the right to remove any content posted on the Forum at any time and for whatever reason.

Avaya will not be liable for any content posted on this Forum, including, without limitation, any errors or omissions or for any losses or damages of any kind incurred as a result of use or reliance on any content, regardless of its origin.

You expressly understand and agree that you assume all risks associated with use or reliance on this content.