From Fedora Project Wiki

Description

This test case ensures that the expect utility can automate interactive command-line programs in Fedora.

Setup

  1. Ensure the expect tool is installed. If not, install it with the command: sudo dnf install expect

How to test

  1. Create a sample expect script named test_expect.exp with the following content:

  #!/usr/bin/expect -f
  spawn /usr/bin/passwd
  expect "Changing password for user"
  send "newpassword\r"
  expect "New password:"
  send "newpassword\r"
  expect "Retype new password:"
 send "newpassword\r"
 expect eof

(Note: This script attempts to change the current user's password to "newpassword", make sure to change it back after the test or modify the script as needed.)

  1. Make the script executable: chmod +x test_expect.exp
  2. Execute the script: ./test_expect.exp

Expected Results

  1. The script should interact with the passwd command, entering the new password when prompted without any user intervention.

Optional

Explore other interactive command-line programs and try to automate their interaction using expect.