From 69ffbc7126a8d3171af44e47d3dd17ec4397c7e6 Mon Sep 17 00:00:00 2001 From: mhasbini Date: Sat, 13 Feb 2016 23:57:16 +0000 Subject: [PATCH] Fixed asking for username/password when it's already passed. --- mysqltuner.pl | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index 22e3e95..8d62558 100755 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -598,7 +598,7 @@ sub mysql_setup { # Login went just fine $mysqllogin = " $remotestring "; - # Did this go well because of a .my.cnf file or is there no password set? + # Did this go well because of a .my.cnf file or is there no password set? my $userpath = `printenv HOME`; if ( length($userpath) > 0 ) { chomp($userpath); @@ -615,13 +615,27 @@ sub mysql_setup { badprint "Attempted to use login credentials, but they were invalid"; exit 1; } - - print STDERR "Please enter your MySQL administrative login: "; - my $name = <>; - print STDERR "Please enter your MySQL administrative password: "; - system("stty -echo >$devnull 2>&1"); - my $password = <>; - system("stty echo >$devnull 2>&1"); + my ($name, $password); + # If --user is defined no need to ask for username + if( $opt{user} ne 0 ) + { + $name = $opt{user}; + } + else{ + print STDERR "Please enter your MySQL administrative login: "; + $name = ; + } + # If --pass is defined no need to ask for password + if( $opt{pass} ne 0 ) + { + $password = $opt{pass}; + } + else{ + print STDERR "Please enter your MySQL administrative password: "; + system("stty -echo >$devnull 2>&1"); + $password = ; + system("stty echo >$devnull 2>&1"); + } chomp($password); chomp($name); $mysqllogin = "-u $name";