Monday, January 11, 2021

Automating responses to scripts on Linux using expect and autoexpect

The Linux expect command takes script writing to an entirely new level. Instead of automating processes, it automates running and responding to other scripts. In other words, you can write a script that asks how you are and then create an expect script that both runs it and tells it that you're ok.

Here's the bash script:

#!/bin/bash

echo "How are you doing?"
read ans

Here's the expect script that provides the response to the query:

#!/usr/bin/expect

set timeout -1
spawn ./ask     # ask is name of script to be run
expect "How are you doing?\r"
send -- "ok\r"
expect eof

When you run the script, you should see this:

To read this article in full, please click here


Thanks to Sandra Henry-Stocker (see source)

No comments:

Post a Comment