LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   bash script: auto-give-password (https://www.linuxquestions.org/questions/linux-software-2/bash-script-auto-give-password-4175600089/)

tonj 02-18-2017 03:54 PM

bash script: auto-give-password
 
I've installed zoneminder 1.30 on centos 6 and the mysql setup needs several commands run to set up the database. I'm trying to write a bash script that automates this setup process but it always stops at this command:
Code:

mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql
and always asks for the password. I've tried loads of different things to automate the password but nothing works. This is my latest try:
Code:

#!/bin/bash
service mysqld start  <--this works fine

/usr/bin/mysql_secure_installation <<EOF

y
secret
secret
y
n
y
y
EOF  <---- this section works fine too

expect -c "
spawn /usr/bin/mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql
expect -nocase \"password:\" {send \"secret\r\"; interact}
"    <--- this stops with command error

I've also tried:
Code:

mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql <<EOF
secret
EOF  <--- this script stops and asks for password

what do I need to do to get this script to give the password automatically?

michaelk 02-18-2017 05:58 PM

Have you tried adding the password?

https://dev.mysql.com/doc/refman/5.7/en/connecting.html

tonj 02-19-2017 06:57 AM

yes thanks for that michaelk, I found that
Quote:

mysql -uroot -psecret < /usr/share/zoneminder/db/zm_create.sql
worked.


All times are GMT -5. The time now is 04:18 PM.