Quantcast
Channel: linuxadmin: Expanding Linux SysAdmin knowledge
Viewing all articles
Browse latest Browse all 17759

Reading user input on a Vagrant shell provisioner script

$
0
0

Hey guys,

I heavily use vagrant in my day-to-day and am just getting around to start scripting out some of my tasks.

One of them I'm working on is a shell provisioner script for setting up mysql secure installation. At one point in the script, I set rootpw1 and rootpw2 to different variables, and create a while loop which looks like this...

while [[ "$rootpw1" != "$rootpw2" ]]; do read -p "what would you like your root password to be > " rootpw1 read -p "please enter the root pw again > " rootpw2 printf '%s\n' "The passwords you entered did not match, please try again" done 

I haven't used while loops a lot so I'm not even sure if the loop would properly break once your passwords match up, but I'm not even getting to that point, and I'm guessing it's something with how vagrant does it's provisioning with shell scripts.

When I run my script, all of the other parts run fine, but when I get to the loop it prints out "The passwords you entered did not match, please try again" twice and then continues the provisioning as normal. I'm not sure if there's something wrong with my while loop, or if you can't use read in a vagrant provisioner shell script.

Anyone else ever run into this?

submitted by /u/charley_chimp
[link] [comments]

Viewing all articles
Browse latest Browse all 17759

Trending Articles