LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-18-2017, 03:54 PM   #1
tonj
Member
 
Registered: Sep 2008
Posts: 523

Rep: Reputation: 37
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?

Last edited by tonj; 02-19-2017 at 06:58 AM. Reason: solved
 
Old 02-18-2017, 05:58 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,605

Rep: Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165
Have you tried adding the password?

https://dev.mysql.com/doc/refman/5.7/en/connecting.html
 
Old 02-19-2017, 06:57 AM   #3
tonj
Member
 
Registered: Sep 2008
Posts: 523

Original Poster
Rep: Reputation: 37
yes thanks for that michaelk, I found that
Quote:
mysql -uroot -psecret < /usr/share/zoneminder/db/zm_create.sql
worked.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
execute bash script with new terminal without give the password ... mythcat Linux - Newbie 1 07-09-2013 05:51 PM
Bash: auto input password how to ? phyyu Linux - Newbie 2 08-28-2010 06:01 AM
how to give password in shell script after scp kushkothari Linux - Networking 2 10-14-2008 12:13 AM
I wondering how to put the password in bash to auto login to others cpu Eatm3Pro Linux - General 2 08-18-2008 04:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration