emyl / vagrant-triggers

Allow the definition of arbitrary scripts that will run on the host before and/or after Vagrant commands.
MIT License
546 stars 35 forks source link

Remote scripts with interaction #65

Closed jxmallett closed 6 years ago

jxmallett commented 8 years ago

Hi. Thanks for the great plugin.

I have a script which I run on halt which backs up the SQL databases of the vagrant machine. I'd like to ask the user for the MySQL password rather than store it in the script. My question is: Is there a way to run scripts on the VM interactively?

My halt script is:

read -s -p "Please enter the MySQL root password: " mysqlRootPassword

while ! mysql -u root -p$mysqlRootPassword  -e ";" ; do
       read -p "Can't connect, please retry: " mysqlRootPassword
done

mysqldump -uroot -p"$mysqlRootPassword" "mydb" > /var/www/vagrant/backup/database/mydb.sql

And my trigger is:

config.trigger.before :halt do
    run_remote "bash /var/www/vagrant/triggers/vagrant_halt"
end

The script triggers correctly but it repeatedly asks for the password without letting me type anything. I just get a stream of Error: Access denied ... Enter Password: messages and all I can do is press ctrl-c to force quit.

Any advice would be much appreciated!