I have an expect script that uses interact every time a password is needed. The program that expect is automating asks for the password multiple times. Is there a way to only have to type the password once and then have expect use it next time the password is asked for? Is there a secure way to do this? I don't want the password saved in a file on the computer as this is not secure.
In terms of securely storing the password, you could use
openssl to generate an MD5 hash of the password, and then compare subsequent inputs against it. This is similar to how
/etc/passwd stores passwords:
openssl passwd -1 -salt j7bJUIHI YOURSECRETPASSWORD
The command will give you a string which you can store in the expect script. When a user inputs the password you'd use
openssl passwd -1 -salt j7bJUIHI $INPUT
and compare against the stored string. If they match, then $INPUT was the correct password. The
-salt string can be anything, but it needs to be fixed between invocations of
openssl to do the comparison correctly.
If you need to retrieve the original password, you can't use this method. Have a look at this entry for a more general discussion on that topic: Hiding Password in Shell Scripts
Sorry, reading this a second time I can see I misunderstood your question. Have a look at the answer here: https://stackoverflow.com/questions/681928/how-can-i-make-an-expect-script-prompt-for-a-password. It looks like the solution you're after.