Latheesan
Latheesan

Reputation: 24116

Parse MySQL Community Edition 5.7 auto-generated temporary root password in bash shell script

I am installing MySQL 5.7 on CentOS 7 (x64) like this:

yum localinstall -y https://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm;
yum install -y mysql-community-server;

The new version of mysql automatically generates a random root password. This can be found with the following command:

grep 'A temporary password is generated for root@localhost' /var/log/mysqld.log | tail -1

e.g. output:

2016-01-01T20:51:50.861279Z 1 [Note] A temporary password is generated for root@localhost: s8,arY7l_xQ:

Is there a way to parse the randomly generated root pass s8,arY7l_xQ: to a variable from the above command's output?

Upvotes: 1

Views: 894

Answers (1)

erik258
erik258

Reputation: 16304

This seems to work for me:

dan@ebony ~ $ cat file
2016-01-01T20:51:50.861279Z 1 [Note] A temporary password is generated for root@localhost: s8,arY7l_xQ:
dan@ebony ~ $ grep 'temporary.*root@localhost' file | sed 's/.*root@localhost: //'
s8,arY7l_xQ:
dan@ebony ~ $ passwd="`grep 'temporary.*root@localhost' file | sed 's/.*root@localhost: //'`"
dan@ebony ~ $ echo $passwd
s8,arY7l_xQ:

Upvotes: 1

Related Questions