Writing a shell script inevitably encounters the steps that require interactive input instructions:
Method One:
# Cat Action.sh
#!/bin/sh
Read-p "Enter Number:" No;
Read-p "Enter Number:" Name;
echo you have entered $no, $name;
# sh action.sh
Enter Number:chavin
Enter number:king
You have entered chavin,king
# echo-e "chavin\nking\n" | SH action.sh
You have entered chavin,king
Or
# echo-e "chavin\nking\n" > Input.data
# Cat Input.data
Chavin
King
# sh action.sh < Input.data
You have entered chavin,king
Case 1: Use interactive automation to change passwords for users:
# Useradd Chavin0101
# echo-e "dbking588\ndbking588\n" | passwd chavin0101
Changing password for user chavin0101.
New Password:retype New Password:passwd:all authentication tokens updated successfully.
Method Two:
Using expect for interactive task automation, the expect tool is not installed by default in the general release and requires manual installation, which is not demonstrated here.
Shell scripts automate interactive input by sending a \ n string or expect script