- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- General
- >
- need info on expect script
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Latin America
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
07-26-2007 09:14 PM
07-26-2007 09:14 PM
i am trying to write a expect script.which doeas not ask 4 a password.The password shd be inside the expect script.
ex:i want to connect to root@34.343.4.3 pasword=xxxxx.
how to do it inside the script.give an example.thnks in advance
Solved! Go to Solution.
- Tags:
- expect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
07-26-2007 10:07 PM
07-26-2007 10:07 PM
Solution--- start ---
#!/usr/bin/expect
log_user 0
set my_passphrase "passphrase"
set my_password "password"
spawn "/usr/bin/ssh" "root@34.343.4.3"
while {1} {
expect {
"continue connecting (yes/no)?" {
send "yes\n"
}
"passphrase" {
send "$my_passphrase\n"
}
"password" {
send "$my_password\n"
}
-re "(#|\\\$|%) $" {
log_user 1
send_user "Shell prompt found. Dropping to shell:"
send "\n"
break
}
}
}
interact
--- end ---
This has separate variables for pass phrases and pass words. Passphrases are for local keys if used. Passwords are for remote authentication.
It also catches the havent-ssh'd-to-the-box-before thing too.
The last bit (the '-re' bit) is the line to see if it finds a shell prompt. If not, there's a built-in 10 second timeout which will dump you out.
The 'interact' at the end should be fairly self explanatory.
If you want to pass the password/passphrase, then you'll need to mess around with the '[lindex argv]' TCL variable stuff.
If all else fails, try using 'autoexpect'. It will generate a custom script for you to modify.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
07-26-2007 10:47 PM
07-26-2007 10:47 PM
Re: need info on expect script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
07-27-2007 12:13 AM
07-27-2007 12:13 AM
Re: need info on expect script
log_user 0
This tells expect to not show any of the spawn's output. Makes it looks neat 'n pretty :P
set
Simple variable assignment. Strictly speaking, the quotes aren't needed for plain text strings (either here, or in the expect strings), but it makes it easier to differentiate what's what.
spawn
This forks off the command, tieing STDIN, STDERR and STDOUT to expect for it to parse/manipulate.
The 'while {1} {' loop is so we don't have to repeat the expect strings over and over.
expect {
The simple form of 'expect' is to take the match string and the command all on the one line (i.e. 'expect "passphrase" send "$my_passphrase\n"').
But as we have multiple possible strings which might match, we use the more open form of the expect command. From here, we list the possible match texts:
"continue connecting (yes/no)?"
"passphrase"
"password"
-re "(#|\\\$|%) $"
The first three should be straight forward and easy to understand. The fourth does a 'regular expression' match on the STDOUT string from the spawned process.
The 'send' command is used to send a string to the spawned process's STDIN.
The 'send_user' is to send text to the user's TTY.
The 'break' is to break out of the while loop.
And finally, we come to the:
interact
As I think I mentioned before, this throws back interactive control to your TTY for you to do things with.
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP