LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-15-2009, 01:41 AM   #1
hasan_sust
LQ Newbie
 
Registered: May 2007
Posts: 23

Rep: Reputation: 0
Expect script to ssh a switch


Hi there

I want to login a switch remotely using expect script. Problem arises when
I want to pass password. Switch's password Contains a $(dollar)sign. So when I execute the script it shows error, like as follows

# ./switchtest
spawn ssh root@x.x.x.x
root@x.x.x.x's password: can't read "H": no such variable
while executing
"send " FyPyNyT@$H\r""
(file "./switchtest" line 7)


Full Code is as follows
=======================
#!/usr/bin/expect

set timeout -1
spawn ssh root@x.x.x.x
expect "root@x.x.x.x's password:"
send " FyPyNyT@$H\r"
expect ">"
send "enable\r"
expect "password:"
send " FyPyNyT@$H\r"
expect "#"
interact


My problems:
1. is there any way to pass password in the form of a variable?
2. any way to read password from any text file and send it to switch?

I need the code. Thanks in advance.

Cheers
HASAN
 
Old 09-15-2009, 02:15 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
Hi,

Ref: http://en.wikipedia.org/wiki/Expect

Quote:
#read the input parameters
set user [lindex $argv 0]
set passw [lindex $argv 1]
set host [lindex $argv 2]
set location [lindex $argv 3]
set file1 [lindex $argv 4]
set file2 [lindex $argv 5]

Looks like you just need to decide how many arguments you would like to provide and then use the appropriate index for your 'host' argument


cheers
 
Old 09-15-2009, 09:34 PM   #3
hasan_sust
LQ Newbie
 
Registered: May 2007
Posts: 23

Original Poster
Rep: Reputation: 0
Expect Script to ssh a switch

Thanks for the link. But it didn't served my purpose.

Please see my code and mention How I implement this on my code.

Thanks anyway.
 
Old 09-15-2009, 09:44 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,811

Rep: Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190
Quote:
Originally Posted by hasan_sust View Post
Thanks for the link. But it didn't served my purpose.

Please see my code and mention How I implement this on my code.

Thanks anyway.
Try putting a backslash (\) in front of the $, like
Code:
"send FyPyNyT\@\$H\r"
that normally 'escapes' characters, and treats them as such, rather than as a control-character. Also, putting a password into ANY script is VERY insecure. Since you're using SSH, I'd strongly suggest using a key-swap, so you can do passwordless-logins, and yet remain secure. It will also greatly simplify your script, too....
 
Old 09-15-2009, 10:22 PM   #5
hasan_sust
LQ Newbie
 
Registered: May 2007
Posts: 23

Original Poster
Rep: Reputation: 0
Thanks man. Putting backslash do the trick.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 09:06 PM
Auto SSH-login expect script creatorrr Linux - Software 7 10-26-2011 03:09 AM
LXer: Using expect to find a MAC Address on a CISCO IOS Switch LXer Syndicated Linux News 0 10-20-2008 03:10 AM
How to use EXPECT command to scp or ssh? thefountainhead100 Linux - Software 6 03-28-2008 06:41 PM
How to partition, if you expect to switch distros? adasiak Linux - General 14 10-05-2007 07:14 PM


All times are GMT -5. The time now is 08:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration