This article is also available in the following other languages / Dieser Beitrag ist auch in folgenden anderen Sprachen verfügbar: Deutsch

Shell Scripts: Automate User Input

2020-05-21 - christian - ansible, bash, linux, shell

The tool expect makes it possible to automate keyboard inputs in shell scripts and programs.

#!/usr/bin/expect
set timeout 600
spawn /usr/share/jitsi-meet/scripts/install-letsencrypt-cert.sh
expect "* email * \\\[ENTER\\\]: "
send "mail@example.com\n"
expect eof

Execute just like a “normal” shell script:

chmod a+x expect-script
./expect-script

expect starts the actual program, waits for the input of Enter your email and press [ENTER]: and types in the email address afterwards.

As Ansible task

- name: Execute lets encrypt bootstrap script
  shell: |
    set timeout 600
    spawn /usr/share/jitsi-meet/scripts/install-letsencrypt-cert.sh
    expect "* email * \\\[ENTER\\\]: "
    send "mail@example.com\n"
    expect eof
  args:
    executable: /usr/bin/expect
  environment:
    DEBIAN_FRONTEND: noninteractive

serverless.industries BG by Carl Lender (CC BY 2.0)
fa7dff93 2020-10-25 21:40