i'm created bash script where i need to configure network, but in one of stage he ask me to save new rule, how to prevent it and set "Yes" automatically.
sudo iptables -t nat -A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 1443
sudo apt-get -y install iptables-persistent
sudo service netfilter-persistent save
For non-terminal programs
Actually, you can always automatize input of eny word with several methods:
yes word | command
(in this word
will be entered as an input of command
)
or using expect
, if you need more sophisticated dialog.
For terminal programs (your case)
For interactive sessions you can try it this way:
tmux send-keys
That is exactly what you want.
tmux send-keys Enter
Everything combined:
sudo tmux -L dialog-session new-session -d service netfilter-persistent save
sudo tmux -L dialog-session send-keys Enter
(actually you don't need sudo
here, but I use sudo
because of your sudo
)