2
2

More than 5 years have passed since last update.

bashで安全にパスワードを入力させる

Posted at
enter_password.sh
#! /bin/bash

read -sp "Enter password: " password
tty -s && echo

schema_list=`mysql --defaults-extra-file=<(printf '[client]\npassword=%s\n' $password) -u root -N -e "SHOW DATABASES;"`

for schema in $schema_list
do
    if [ $schema != mysql -a  $schema != information_schema -a $schema != performance_schema ]; then
        mysql --defaults-extra-file=<(printf '[client]\npassword=%s\n' $password) -u root -e "CREATE TABLE $schema.test_table (id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, name CHAR(20) NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB;"
    fi
done
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2