Expect type functionality in Action Scripts?

In Solaris (I know… another Solaris question…) it is possible to install a scripting program that allows you to look for specific output from a system, and then send specific responses back to that system. One example would be logging into a system with a password, that can be sent by this script.

I was wondering if there is something like that built into Action scripts? I’d prefer not to install the package on all of the Solaris machines if there was a way to use this ability with IEM.

an example of the code would look like this:

spawn login_and_ls.sh
expect "Password: "
send "PASSWORD\r"
expect "$ "
send "ls\r"
expect "$ "

Thanks,
Bob_K

The actionscript language doesn’t deal well with the standard console in/out type streams etc (stdout/stderr etc). You can do this probably within some other package like you mentioned but there isn’t any native item there. I presume the shells you use can’t even do this natively?

You can run any command through IEM, output the results to a file, then read that file using relevance… This seems a bit like what you are trying to do.

Depending on what you are trying to do, you might be able to query the results directly through relevance.

Do you have a specific use case?

@jgstew:

Here is the expect script code that would accomplish what I’m doing:

spawn /usr/sbin/eeprom security-mode=command
expect "w password:"
send "{parameter "password"}\r"
expect "w password:"
send "{parameter "password"}\r"
expect "$ -> "

I’d prefer not to use an expect script, since expect isn’t available on all target machines.

it runs the command:
/usr/sbin/eeprom security-mode=command

which will then ask for a new password to be entered twice (to set new password)

@AlanM:

No, this cannot be done natively…

Thanks,
Bob_K

I am quite certain that it should be possible to do this using BigFix/IEM.

I don’t have any way of testing this, but if there is a way to do this on a single line, then that would be an option. Something like this:

wait sh -c "echo "{parameter "password"}$'\n'{parameter "password"}$'\n'" | /usr/sbin/eeprom security-mode=command"

The only other option would be to run an actual script that would do this, which might not need to use expect. You could write relevance to look for expect so that you would only try to run the version using expect on systems that have it, and do it differently without using expect on machines that lack it.


References:

http://bigfix.me/fixlet/details/3673
http://docs.oracle.com/cd/E19253-01/816-5166/eeprom-1m/
http://www.lehman.cuny.edu/cgi-bin/man-cgi?eeprom+1
http://linux.die.net/man/1/expect
http://www.pearsonitcertification.com/articles/article.aspx?p=440286&seqNum=8
http://steve-parker.org/sh/expect.shtml

@jgstew,

Unfortunately, this doesn’t work. I tried several combinations of quotes and no luck. I believe that was part of the reason why expect was created to begin with. For situations like this…

Thanks,
Bob_K

1 Like

You could just run the script that uses expect on the systems that have expect. On systems that do not have expect, you could download a copy of expect for that system and use it on the fly.

What happens if you try to specify the password on the command line?

Something like this:

wait /usr/sbin/eeprom security-mode=command security-password={parameter "password"}

Also, this will basically do what expect does, but without expect:

http://steve-parker.org/sh/expect.shtml


Also, I think my previous attempt was using the wrong end of line character:

wait sh -c "echo "{parameter "password"}$'\r'{parameter "password"}$'\r'" | /usr/sbin/eeprom security-mode=command"

These are all things you should try to get to work using a single line on the command line first before attempting to automate through BigFix/IEM because it will take many attempts to figure out the correct syntax, if it is possible at all.

So to attempt this on the command line:

echo "PASSWORD_VALUE$'\r'PASSWORD_VALUE$'\r'" | /usr/sbin/eeprom security-mode=command

You definitely can do this through BigFix/IEM by creating a bash script using the create file command and then running it, but it would either need to use expect or that alternative script I linked above.

jgstew,

wait /usr/sbin/eeprom security-mode=command security-password={parameter "password"}

The security-password text is ignored, because user is already prompted for password when you use:

/usr/sbin/eeprom security-mode=command

Trying to use the expect type shell script, the prompts for New password: and Retype new password: are getting sent to the console, not the file1 file, so the E lines aren’t finding the expected text…

echo "PASSWORD_VALUE$'\r'PASSWORD_VALUE$'\r'" | /usr/sbin/eeprom security-mode=command

I get prompted for:

Changing PROM password:
New Password:

but the result of the echo is not taken as input.

Thanks for all your effort in trying to figure this out. It looks like the only way to go with this is to have expect loaded on each machine. I would have much preferred using a solution that could be housed completely on IEM.

Bob_K

1 Like

I find it odd that there isn’t a solution for this somewhere. This isn’t so much a limitation of BigFix/IEM as it is a limitation of the ability to script eeprom security-mode=command non-interactively. If there was a way to do this using a shell script without using expect, then that should also work in BigFix/IEM. Same goes if there is a way to do it with a single line.

I don’t have a system that uses this command, so I don’t have any experience with it or a way to experiment.


You don’t need to load expect on each machine ahead of time. You can download expect and use it only on the machines that do not have it already, and the machines that do have it already can just use the existing copy. You can do this in a prefetch block.

This is basically how I do installs that require unzip.exe without requiring it be on the system in the first place.


See these examples:

http://bigfix.me/fixlet/details/2608
http://bigfix.me/fixlet/details/3896

Try this:

/usr/sbin/eeprom security-mode=command <<< "PASSWORD_VALUE\rPASSWORD_VALUE\r"