Skip to contentSkip to conversation

expect

DISCUSSION Russell Coker 2 participants 4 messages Oct 26, 2002 1 message not in the archive SELinux security module

lore
Share & tools
lore
#0 lore raw

I want to run an expect script as:
script program param1 param2 ...

Then have the script spawn "program param1 param2" (sort of like "$@" in a bash script). How do I do this? Expect wants to combine all the parameters into a single parameter that contains spaces. How can I solve this?

Also I want to do it for a varying number of parameters (so having an entry for each parameter isn't going to work).

The aim of this is to provide the open_init_pty functionality. The version I posted to the list before will work for the basic SE functionality (IE Slackware type support). But for Debian support (and for full RPM support when someone implements it) we need to have open_init_pty run dpkg to install packages (and we can install multiple packages at the same time).

Signature · 10 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 11 lines · Russell Coker

I want to run an expect script as:
script program param1 param2 ...

Then have the script spawn "program param1 param2" (sort of like "$@" in a bash script). How do I do this? Expect wants to combine all the parameters into a single parameter that contains spaces. How can I solve this?

Also I want to do it for a varying number of parameters (so having an entry for each parameter isn't going to work).

The aim of this is to provide the open_init_pty functionality. The version I posted to the list before will work for the basic SE functionality (IE Slackware type support). But for Debian support (and for full RPM support when someone implements it) we need to have open_init_pty run dpkg to install packages (and we can install multiple packages at the same time).

Russel,
Is is as you woud ex... imagine-- argv.

$expect script param1 param2 ... paramn

All the parameters are found in the list 'argv' , so if in script
...
set argc [llength $argv]
for (set i 0) {$i < $argc} {incr i} {
puts "arg $i: [lindex $argv $i]"
}

...

Then the script will spit out:

...

arg 0: param1
arg 1: param2
...
arg n: paramn
...

As in D.Libes' "Exploring Expect" (Oreilly)

Chris

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
Quoted 3 lines · Chris Albert
Quoted 2 lines · Russell Coker

I want to run an expect script as:
script program param1 param2 ...

OK, I think I didn't make it clear what I want to do. Say I want to run ls with a variety of parameters, I save the following as /tmp/testit:

#!/usr/bin/expect

spawn /bin/ls [lrange $argv 0 end]
interact

Then I type the following command:
/tmp/testit -l -a /tmp

I want the same result as "ls -l -a /tmp" but I don't get it.

Signature · 10 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Excellent! That's what I need!

Quoted 12 lines · Chris Albert

maybe what you want is:

/tmp/testit
#!/usr/bin/expect
eval spawn -noecho $argv

And then run:

./testit.sh ls -a -l /tmp

Chris

Signature · 10 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.