Skip to content

Expect and bash

wordpress meta

title: 'Expect and bash'
date: '2017-01-19T15:07:31-06:00'
status: publish
permalink: /expect-and-bash
author: admin
excerpt: ''
type: post
id: 1029
    - Bash
    - Expect
tag: []
post_format: []

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.

$ cat
echo "Enter the password: "
read -s -e password
./expect_example.exp $password ;

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