Skip to main content
Logo

Expect and bash

January 18, 2017
1 min read

Quick example of spawning a problem that have a password prompt and can”t accept a documented parameter for a password. I used another bash script to simulate a password prompt but in my automation challenge it was an executable that prompted.

Main script just to take a password for passing to expect. Could also be hard coded.

catexpect_example_main.sh#!/bin/bashecho"Enterthepassword:"readsepassword./expect_example.expcat expect\_example\_main.sh \#!/bin/bash echo "Enter the password: " read -s -e password ./expect\_example.exppassword ;

Here is the expect script that will be interacting with the real program with the password prompt.

$ cat expect_example.exp
#!/usr/bin/expect -f

# Set variables
set password [lindex $argv 0]
set date [exec date +%F]

# Log results
log_file -a expect-$date.log

# Announce device & time
send_user “\n”
send_user ”>>>>> Working @ [exec date] >>>> Working @ Thu Jan 19 14:54:00 CST 2017 >>>> Working @ Thu Jan 19 14:54:28 CST 2017