Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

bash: filling user read input automatically with param list

I’m trying to use Wireguard road-warrior script from here https://github.com/Nyr/wireguard-install

But i cant make it run in noninteractive mode with predefined parameters. I’ve read some other similar topics here about how to provide answers to bash "read", but suggestions from there doesn’t work.

I’ve tried this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

# bash wireguard-install.sh < params
# printf '%s\n' 51822 clientcustom 2 y | bash wireguard-install.sh
# echo "51822 clientcustom 2 y" | bash wireguard-install.sh

in every case installer just uses default values. What am i doing wrong?

>Solution :

https://github.com/Nyr/wireguard-install/blob/master/wireguard-install.sh#L15

Indeed, this is a bit problematic. Typically, not caring, you would just:

( sleep 1; printf '%s\n' 51822 clientcustom 2 y ) | ...

A real robust solution, you would parse the output of the process to know when to write response, either with expect or Bash or something better.

coproc bash wireguard-install.sh
while IFS= read -r -u "${COPROC[0]}" line; do
    case "$line" in
    "IPv4 address [1]:"*) echo something >&"${COPROC[1]}"; ;;
    "other prompt"*) echo other stuff >&"${COPROC[1]}"; ;;
    "etc...") echo ... ;;
    esac
done
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading