For instance, when installing MySQL I would like to automatically run some commands and answer a few questions:
$ sudo mysql_secure_installation Enter current password for root (enter for none): Type root password Change the root password? N Remove anonymous users? Y Disallow root login remotely? Y Remove test database and access to it? Y Reload privilege tables now? Y I want to make a script that installs and automatically provides the answers to the configuration questions. How can I pass the MySQL configuration routine values based on set variables?
Edit[2015/04/18]:
Found a way:
echo -e "\npassword1\ny\npassword2\npassword2\ny\ny\ny\ny" | sudo /usr/bin/mysql_secure_installation Its a bit messy but works, but i think hek2mgl answer is more readable.