LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 08-22-2009, 01:00 AM   #1
jprathap
LQ Newbie
 
Registered: Nov 2008
Location: India
Posts: 9

Rep: Reputation: 0
How To pass argument in Expect command?


Hi all,

Could you plz tell me the syntax of passing the arguments in the expect script.
 
Old 08-22-2009, 02:11 AM   #2
kris82
LQ Newbie
 
Registered: Dec 2008
Distribution: Fedora 10/11
Posts: 10

Rep: Reputation: 1
to pass arguments into anything....

command [arguments]

but I think you are talking more like passing output into the command...

so, use a pipe...

command | expect.....

this takes command and feeds it into expect...
 
Old 08-27-2009, 07:31 AM   #3
jprathap
LQ Newbie
 
Registered: Nov 2008
Location: India
Posts: 9

Original Poster
Rep: Reputation: 0
Question How To pass argument in Expect command?

Hi

I have script like this

#!/usr/bin/expect -f
spawn ssh user@192.168.2.3
expect "password: "
send "mypassword\r"
interact

My doubt is how to get the password as an argument . In this script. Is there way to get the argument like in shell ( $1).

Last edited by jprathap; 08-27-2009 at 07:34 AM.
 
Old 08-27-2009, 04:58 PM   #4
rnturn
Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: Red Hat (8.0), SuSE (10.x, 11.x, 12.2), Solaris (8-10), Tru64
Posts: 949

Rep: Reputation: 51
Quote:
Originally Posted by jprathap View Post
My doubt is how to get the password as an argument . In this script. Is there way to get the argument like in shell ( $1).
The simplest way would be to change your script to:

Code:
#!/usr/bin/expect -f

set mypassword [lindex $argv 0]

spawn ssh user@192.168.2.3
expect "password: "
send "$mypassword\r"
interact
If you want to pass additional arguments, they would be accessible using additional lines:
Code:
set arg2 [lindex $argv 1]
set arg3 [lindex $argv 2]
and so on.

Good luck.

--
RT
 
1 members found this post helpful.
  


Reply

Tags
expect


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
How do I pass command to gnome-terminal as an argument? crasywolf Linux - Newbie 5 05-11-2010 09:00 AM
Pass argument to module in grub Racuel Linux - Kernel 1 04-21-2009 10:27 PM
[SOLVED] pass file-name as command line argument vikas027 Programming 2 10-14-2008 11:52 PM
Pass argument between php scripts gandalf_the_grey Linux - Newbie 1 02-03-2006 02:53 PM
How to pass an argument to DHCPCD ? shazam75 Linux - Networking 3 02-27-2005 10:34 AM


All times are GMT -5. The time now is 10:45 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration