Suppress warning messages from MySQL in shell script but allow errors
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
My log files are getting dumped with following message while running shell scripts using some underlying MySQL commands.
Here is the message:
"Warning: Using a password on the command line interface can be insecure."
To stop these messages, I am using the following job definition.
Example:
run_wrapper.sh |grep -v "Warning: Using a password" > output.log 2>&1
This worked but the MySQL errors are not being logged to output.log
.
If I change the definition like the following, then MySQL errors start appearing if any
run_wrapper.sh > output.log 2>&1
So the question is how to suppress the warning messages and also report SQL errors in log files using only the cron definition?
shell-script logs io-redirection mysql
add a comment |Â
up vote
6
down vote
favorite
My log files are getting dumped with following message while running shell scripts using some underlying MySQL commands.
Here is the message:
"Warning: Using a password on the command line interface can be insecure."
To stop these messages, I am using the following job definition.
Example:
run_wrapper.sh |grep -v "Warning: Using a password" > output.log 2>&1
This worked but the MySQL errors are not being logged to output.log
.
If I change the definition like the following, then MySQL errors start appearing if any
run_wrapper.sh > output.log 2>&1
So the question is how to suppress the warning messages and also report SQL errors in log files using only the cron definition?
shell-script logs io-redirection mysql
probably you should userun_wrapper.sh >> output.log 2>&1
â Rahul
Jul 5 '16 at 9:17
1
I'm not following. Where would you want error/warnings to go and where would you want output to go, and what would you want to throw away? What is generating the password warning and why do you have errors in the MySQL that you don't want to fix?
â Kusalananda
Jul 5 '16 at 9:38
1
mysql prints that warning when you use the-p
option on the command line. Instead of fixing it (e.g. by creating a~/.my.cnf
with 600 perms) the OP wants to just ignore and discard the warning (and only that warning, not all of stderr)
â cas
Jul 5 '16 at 13:10
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
My log files are getting dumped with following message while running shell scripts using some underlying MySQL commands.
Here is the message:
"Warning: Using a password on the command line interface can be insecure."
To stop these messages, I am using the following job definition.
Example:
run_wrapper.sh |grep -v "Warning: Using a password" > output.log 2>&1
This worked but the MySQL errors are not being logged to output.log
.
If I change the definition like the following, then MySQL errors start appearing if any
run_wrapper.sh > output.log 2>&1
So the question is how to suppress the warning messages and also report SQL errors in log files using only the cron definition?
shell-script logs io-redirection mysql
My log files are getting dumped with following message while running shell scripts using some underlying MySQL commands.
Here is the message:
"Warning: Using a password on the command line interface can be insecure."
To stop these messages, I am using the following job definition.
Example:
run_wrapper.sh |grep -v "Warning: Using a password" > output.log 2>&1
This worked but the MySQL errors are not being logged to output.log
.
If I change the definition like the following, then MySQL errors start appearing if any
run_wrapper.sh > output.log 2>&1
So the question is how to suppress the warning messages and also report SQL errors in log files using only the cron definition?
shell-script logs io-redirection mysql
edited Jul 9 '16 at 18:55
Jeff Schaller
31.2k846105
31.2k846105
asked Jul 5 '16 at 9:03
jagadish puvvada
31113
31113
probably you should userun_wrapper.sh >> output.log 2>&1
â Rahul
Jul 5 '16 at 9:17
1
I'm not following. Where would you want error/warnings to go and where would you want output to go, and what would you want to throw away? What is generating the password warning and why do you have errors in the MySQL that you don't want to fix?
â Kusalananda
Jul 5 '16 at 9:38
1
mysql prints that warning when you use the-p
option on the command line. Instead of fixing it (e.g. by creating a~/.my.cnf
with 600 perms) the OP wants to just ignore and discard the warning (and only that warning, not all of stderr)
â cas
Jul 5 '16 at 13:10
add a comment |Â
probably you should userun_wrapper.sh >> output.log 2>&1
â Rahul
Jul 5 '16 at 9:17
1
I'm not following. Where would you want error/warnings to go and where would you want output to go, and what would you want to throw away? What is generating the password warning and why do you have errors in the MySQL that you don't want to fix?
â Kusalananda
Jul 5 '16 at 9:38
1
mysql prints that warning when you use the-p
option on the command line. Instead of fixing it (e.g. by creating a~/.my.cnf
with 600 perms) the OP wants to just ignore and discard the warning (and only that warning, not all of stderr)
â cas
Jul 5 '16 at 13:10
probably you should use
run_wrapper.sh >> output.log 2>&1
â Rahul
Jul 5 '16 at 9:17
probably you should use
run_wrapper.sh >> output.log 2>&1
â Rahul
Jul 5 '16 at 9:17
1
1
I'm not following. Where would you want error/warnings to go and where would you want output to go, and what would you want to throw away? What is generating the password warning and why do you have errors in the MySQL that you don't want to fix?
â Kusalananda
Jul 5 '16 at 9:38
I'm not following. Where would you want error/warnings to go and where would you want output to go, and what would you want to throw away? What is generating the password warning and why do you have errors in the MySQL that you don't want to fix?
â Kusalananda
Jul 5 '16 at 9:38
1
1
mysql prints that warning when you use the
-p
option on the command line. Instead of fixing it (e.g. by creating a ~/.my.cnf
with 600 perms) the OP wants to just ignore and discard the warning (and only that warning, not all of stderr)â cas
Jul 5 '16 at 13:10
mysql prints that warning when you use the
-p
option on the command line. Instead of fixing it (e.g. by creating a ~/.my.cnf
with 600 perms) the OP wants to just ignore and discard the warning (and only that warning, not all of stderr)â cas
Jul 5 '16 at 13:10
add a comment |Â
5 Answers
5
active
oldest
votes
up vote
9
down vote
In your bash script, edit it at top
export MYSQL_PWD=yourdbpassword
and mysql query like: mysql -u username -h host db -e "statement"
Reference: From answer posted at Stackoverflow. Other answers can also be followed.
add a comment |Â
up vote
1
down vote
It looks like you're missing the stderr redirection from run_wrapper.sh
itself, so the errors aren't going through the grep
and thence to the log file.
Try this instead if you're happy to have both stdout and sdterr written to your logfile
run_wrapper.sh 2>&1 | grep -v "Warning: Using a password" > output.log
Or if you want only the errors written to the logfile, and stdout left writing to the calling terminal, try this
( run_wrapper.sh 2>&1 1>&3 | grep -v "Warning: Using a password" > output.log ) 3>&1
add a comment |Â
up vote
0
down vote
Try this:
lf='output.log'
> "$lf" # first truncate/create the logfile.
run_wrapper.sh >> "$lf" 2> >(grep -v "Warn.*passw.*insec" >> "$lf")
Redirects stderr via Process Substitution to grep -v ...
, and output from that is appended with >>
to output.log
You probably want to use (GNU) grep
's --line-buffered
option as well as -v
to make sure error output isn't delayed.
If post-processing the log file is an acceptable option for you, you could just delete the unwanted "Warning: " line(s) from the log file after run_wrapper.sh
has finished.
The following shell script fragment saves the timestamp (in $ts
) of the log file (in $lf
) before running sed -i
and restores it afterwards:
lf='output.log'
run_wrapper.sh >& "$lf"
ts=$(date -r "$lf" '+%Y%m%d%H%M.%S')
sed -i -e '/Warning: Using a password/d' "$lf"
touch -t "$ts" "$lf"
If you need to preserve the inode of the log file (e.g. because it has hard links), use ed
rather than sed
:
ts=$(date -r "$lf" '+%Y%m%d%H%M.%S')
printf "%sn" 'g/Warning: Using a password/d' w | ed -s "$lf"
touch -t "$ts" "$lf"
Thanks for the response. I have tried the suggested option like below
â jagadish puvvada
Jul 6 '16 at 5:13
sed option creates blank lines and we need to remove them also and it changes file timestamp also
â jagadish puvvada
Jul 8 '16 at 5:06
The post-process-with-sed option also changes the inode as well as the timestamp - that's normal for-i
(and most forms of "in-place" editing"). If run immediately afterwards, it should only be microseconds or seconds different, depending on logfile size of course. But there's no way ad
(delete line) command insed
will create a blank line - what exactly do you mean by that?
â cas
Jul 8 '16 at 5:15
@jagadishpuvvadased
option now saves and restores output.log's timestamp.
â cas
Jul 8 '16 at 12:06
add a comment |Â
up vote
0
down vote
search for a line in your wrapper similar to
mysql -u<username> -p<some_password> -hlocalhost -D<database_name>
and change to
export MYSQL_PWD=<some_password> ; mysql -u<username> -hlocalhost -D<database_name>
this solves the source of the warning.
add a comment |Â
up vote
0
down vote
Try adding this to the end of your command:
/dev/null 2>&1
add a comment |Â
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
9
down vote
In your bash script, edit it at top
export MYSQL_PWD=yourdbpassword
and mysql query like: mysql -u username -h host db -e "statement"
Reference: From answer posted at Stackoverflow. Other answers can also be followed.
add a comment |Â
up vote
9
down vote
In your bash script, edit it at top
export MYSQL_PWD=yourdbpassword
and mysql query like: mysql -u username -h host db -e "statement"
Reference: From answer posted at Stackoverflow. Other answers can also be followed.
add a comment |Â
up vote
9
down vote
up vote
9
down vote
In your bash script, edit it at top
export MYSQL_PWD=yourdbpassword
and mysql query like: mysql -u username -h host db -e "statement"
Reference: From answer posted at Stackoverflow. Other answers can also be followed.
In your bash script, edit it at top
export MYSQL_PWD=yourdbpassword
and mysql query like: mysql -u username -h host db -e "statement"
Reference: From answer posted at Stackoverflow. Other answers can also be followed.
edited Dec 18 '17 at 5:49
answered Jan 5 '17 at 6:45
Lnux
213310
213310
add a comment |Â
add a comment |Â
up vote
1
down vote
It looks like you're missing the stderr redirection from run_wrapper.sh
itself, so the errors aren't going through the grep
and thence to the log file.
Try this instead if you're happy to have both stdout and sdterr written to your logfile
run_wrapper.sh 2>&1 | grep -v "Warning: Using a password" > output.log
Or if you want only the errors written to the logfile, and stdout left writing to the calling terminal, try this
( run_wrapper.sh 2>&1 1>&3 | grep -v "Warning: Using a password" > output.log ) 3>&1
add a comment |Â
up vote
1
down vote
It looks like you're missing the stderr redirection from run_wrapper.sh
itself, so the errors aren't going through the grep
and thence to the log file.
Try this instead if you're happy to have both stdout and sdterr written to your logfile
run_wrapper.sh 2>&1 | grep -v "Warning: Using a password" > output.log
Or if you want only the errors written to the logfile, and stdout left writing to the calling terminal, try this
( run_wrapper.sh 2>&1 1>&3 | grep -v "Warning: Using a password" > output.log ) 3>&1
add a comment |Â
up vote
1
down vote
up vote
1
down vote
It looks like you're missing the stderr redirection from run_wrapper.sh
itself, so the errors aren't going through the grep
and thence to the log file.
Try this instead if you're happy to have both stdout and sdterr written to your logfile
run_wrapper.sh 2>&1 | grep -v "Warning: Using a password" > output.log
Or if you want only the errors written to the logfile, and stdout left writing to the calling terminal, try this
( run_wrapper.sh 2>&1 1>&3 | grep -v "Warning: Using a password" > output.log ) 3>&1
It looks like you're missing the stderr redirection from run_wrapper.sh
itself, so the errors aren't going through the grep
and thence to the log file.
Try this instead if you're happy to have both stdout and sdterr written to your logfile
run_wrapper.sh 2>&1 | grep -v "Warning: Using a password" > output.log
Or if you want only the errors written to the logfile, and stdout left writing to the calling terminal, try this
( run_wrapper.sh 2>&1 1>&3 | grep -v "Warning: Using a password" > output.log ) 3>&1
answered Jul 8 '16 at 12:33
roaima
39.5k545107
39.5k545107
add a comment |Â
add a comment |Â
up vote
0
down vote
Try this:
lf='output.log'
> "$lf" # first truncate/create the logfile.
run_wrapper.sh >> "$lf" 2> >(grep -v "Warn.*passw.*insec" >> "$lf")
Redirects stderr via Process Substitution to grep -v ...
, and output from that is appended with >>
to output.log
You probably want to use (GNU) grep
's --line-buffered
option as well as -v
to make sure error output isn't delayed.
If post-processing the log file is an acceptable option for you, you could just delete the unwanted "Warning: " line(s) from the log file after run_wrapper.sh
has finished.
The following shell script fragment saves the timestamp (in $ts
) of the log file (in $lf
) before running sed -i
and restores it afterwards:
lf='output.log'
run_wrapper.sh >& "$lf"
ts=$(date -r "$lf" '+%Y%m%d%H%M.%S')
sed -i -e '/Warning: Using a password/d' "$lf"
touch -t "$ts" "$lf"
If you need to preserve the inode of the log file (e.g. because it has hard links), use ed
rather than sed
:
ts=$(date -r "$lf" '+%Y%m%d%H%M.%S')
printf "%sn" 'g/Warning: Using a password/d' w | ed -s "$lf"
touch -t "$ts" "$lf"
Thanks for the response. I have tried the suggested option like below
â jagadish puvvada
Jul 6 '16 at 5:13
sed option creates blank lines and we need to remove them also and it changes file timestamp also
â jagadish puvvada
Jul 8 '16 at 5:06
The post-process-with-sed option also changes the inode as well as the timestamp - that's normal for-i
(and most forms of "in-place" editing"). If run immediately afterwards, it should only be microseconds or seconds different, depending on logfile size of course. But there's no way ad
(delete line) command insed
will create a blank line - what exactly do you mean by that?
â cas
Jul 8 '16 at 5:15
@jagadishpuvvadased
option now saves and restores output.log's timestamp.
â cas
Jul 8 '16 at 12:06
add a comment |Â
up vote
0
down vote
Try this:
lf='output.log'
> "$lf" # first truncate/create the logfile.
run_wrapper.sh >> "$lf" 2> >(grep -v "Warn.*passw.*insec" >> "$lf")
Redirects stderr via Process Substitution to grep -v ...
, and output from that is appended with >>
to output.log
You probably want to use (GNU) grep
's --line-buffered
option as well as -v
to make sure error output isn't delayed.
If post-processing the log file is an acceptable option for you, you could just delete the unwanted "Warning: " line(s) from the log file after run_wrapper.sh
has finished.
The following shell script fragment saves the timestamp (in $ts
) of the log file (in $lf
) before running sed -i
and restores it afterwards:
lf='output.log'
run_wrapper.sh >& "$lf"
ts=$(date -r "$lf" '+%Y%m%d%H%M.%S')
sed -i -e '/Warning: Using a password/d' "$lf"
touch -t "$ts" "$lf"
If you need to preserve the inode of the log file (e.g. because it has hard links), use ed
rather than sed
:
ts=$(date -r "$lf" '+%Y%m%d%H%M.%S')
printf "%sn" 'g/Warning: Using a password/d' w | ed -s "$lf"
touch -t "$ts" "$lf"
Thanks for the response. I have tried the suggested option like below
â jagadish puvvada
Jul 6 '16 at 5:13
sed option creates blank lines and we need to remove them also and it changes file timestamp also
â jagadish puvvada
Jul 8 '16 at 5:06
The post-process-with-sed option also changes the inode as well as the timestamp - that's normal for-i
(and most forms of "in-place" editing"). If run immediately afterwards, it should only be microseconds or seconds different, depending on logfile size of course. But there's no way ad
(delete line) command insed
will create a blank line - what exactly do you mean by that?
â cas
Jul 8 '16 at 5:15
@jagadishpuvvadased
option now saves and restores output.log's timestamp.
â cas
Jul 8 '16 at 12:06
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Try this:
lf='output.log'
> "$lf" # first truncate/create the logfile.
run_wrapper.sh >> "$lf" 2> >(grep -v "Warn.*passw.*insec" >> "$lf")
Redirects stderr via Process Substitution to grep -v ...
, and output from that is appended with >>
to output.log
You probably want to use (GNU) grep
's --line-buffered
option as well as -v
to make sure error output isn't delayed.
If post-processing the log file is an acceptable option for you, you could just delete the unwanted "Warning: " line(s) from the log file after run_wrapper.sh
has finished.
The following shell script fragment saves the timestamp (in $ts
) of the log file (in $lf
) before running sed -i
and restores it afterwards:
lf='output.log'
run_wrapper.sh >& "$lf"
ts=$(date -r "$lf" '+%Y%m%d%H%M.%S')
sed -i -e '/Warning: Using a password/d' "$lf"
touch -t "$ts" "$lf"
If you need to preserve the inode of the log file (e.g. because it has hard links), use ed
rather than sed
:
ts=$(date -r "$lf" '+%Y%m%d%H%M.%S')
printf "%sn" 'g/Warning: Using a password/d' w | ed -s "$lf"
touch -t "$ts" "$lf"
Try this:
lf='output.log'
> "$lf" # first truncate/create the logfile.
run_wrapper.sh >> "$lf" 2> >(grep -v "Warn.*passw.*insec" >> "$lf")
Redirects stderr via Process Substitution to grep -v ...
, and output from that is appended with >>
to output.log
You probably want to use (GNU) grep
's --line-buffered
option as well as -v
to make sure error output isn't delayed.
If post-processing the log file is an acceptable option for you, you could just delete the unwanted "Warning: " line(s) from the log file after run_wrapper.sh
has finished.
The following shell script fragment saves the timestamp (in $ts
) of the log file (in $lf
) before running sed -i
and restores it afterwards:
lf='output.log'
run_wrapper.sh >& "$lf"
ts=$(date -r "$lf" '+%Y%m%d%H%M.%S')
sed -i -e '/Warning: Using a password/d' "$lf"
touch -t "$ts" "$lf"
If you need to preserve the inode of the log file (e.g. because it has hard links), use ed
rather than sed
:
ts=$(date -r "$lf" '+%Y%m%d%H%M.%S')
printf "%sn" 'g/Warning: Using a password/d' w | ed -s "$lf"
touch -t "$ts" "$lf"
edited Jul 8 '16 at 12:12
answered Jul 5 '16 at 13:03
cas
37.6k44392
37.6k44392
Thanks for the response. I have tried the suggested option like below
â jagadish puvvada
Jul 6 '16 at 5:13
sed option creates blank lines and we need to remove them also and it changes file timestamp also
â jagadish puvvada
Jul 8 '16 at 5:06
The post-process-with-sed option also changes the inode as well as the timestamp - that's normal for-i
(and most forms of "in-place" editing"). If run immediately afterwards, it should only be microseconds or seconds different, depending on logfile size of course. But there's no way ad
(delete line) command insed
will create a blank line - what exactly do you mean by that?
â cas
Jul 8 '16 at 5:15
@jagadishpuvvadased
option now saves and restores output.log's timestamp.
â cas
Jul 8 '16 at 12:06
add a comment |Â
Thanks for the response. I have tried the suggested option like below
â jagadish puvvada
Jul 6 '16 at 5:13
sed option creates blank lines and we need to remove them also and it changes file timestamp also
â jagadish puvvada
Jul 8 '16 at 5:06
The post-process-with-sed option also changes the inode as well as the timestamp - that's normal for-i
(and most forms of "in-place" editing"). If run immediately afterwards, it should only be microseconds or seconds different, depending on logfile size of course. But there's no way ad
(delete line) command insed
will create a blank line - what exactly do you mean by that?
â cas
Jul 8 '16 at 5:15
@jagadishpuvvadased
option now saves and restores output.log's timestamp.
â cas
Jul 8 '16 at 12:06
Thanks for the response. I have tried the suggested option like below
â jagadish puvvada
Jul 6 '16 at 5:13
Thanks for the response. I have tried the suggested option like below
â jagadish puvvada
Jul 6 '16 at 5:13
sed option creates blank lines and we need to remove them also and it changes file timestamp also
â jagadish puvvada
Jul 8 '16 at 5:06
sed option creates blank lines and we need to remove them also and it changes file timestamp also
â jagadish puvvada
Jul 8 '16 at 5:06
The post-process-with-sed option also changes the inode as well as the timestamp - that's normal for
-i
(and most forms of "in-place" editing"). If run immediately afterwards, it should only be microseconds or seconds different, depending on logfile size of course. But there's no way a d
(delete line) command in sed
will create a blank line - what exactly do you mean by that?â cas
Jul 8 '16 at 5:15
The post-process-with-sed option also changes the inode as well as the timestamp - that's normal for
-i
(and most forms of "in-place" editing"). If run immediately afterwards, it should only be microseconds or seconds different, depending on logfile size of course. But there's no way a d
(delete line) command in sed
will create a blank line - what exactly do you mean by that?â cas
Jul 8 '16 at 5:15
@jagadishpuvvada
sed
option now saves and restores output.log's timestamp.â cas
Jul 8 '16 at 12:06
@jagadishpuvvada
sed
option now saves and restores output.log's timestamp.â cas
Jul 8 '16 at 12:06
add a comment |Â
up vote
0
down vote
search for a line in your wrapper similar to
mysql -u<username> -p<some_password> -hlocalhost -D<database_name>
and change to
export MYSQL_PWD=<some_password> ; mysql -u<username> -hlocalhost -D<database_name>
this solves the source of the warning.
add a comment |Â
up vote
0
down vote
search for a line in your wrapper similar to
mysql -u<username> -p<some_password> -hlocalhost -D<database_name>
and change to
export MYSQL_PWD=<some_password> ; mysql -u<username> -hlocalhost -D<database_name>
this solves the source of the warning.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
search for a line in your wrapper similar to
mysql -u<username> -p<some_password> -hlocalhost -D<database_name>
and change to
export MYSQL_PWD=<some_password> ; mysql -u<username> -hlocalhost -D<database_name>
this solves the source of the warning.
search for a line in your wrapper similar to
mysql -u<username> -p<some_password> -hlocalhost -D<database_name>
and change to
export MYSQL_PWD=<some_password> ; mysql -u<username> -hlocalhost -D<database_name>
this solves the source of the warning.
answered May 14 '17 at 14:48
Mockler
1
1
add a comment |Â
add a comment |Â
up vote
0
down vote
Try adding this to the end of your command:
/dev/null 2>&1
add a comment |Â
up vote
0
down vote
Try adding this to the end of your command:
/dev/null 2>&1
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Try adding this to the end of your command:
/dev/null 2>&1
Try adding this to the end of your command:
/dev/null 2>&1
answered Jun 15 '17 at 1:51
user236164
1
1
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f293966%2fsuppress-warning-messages-from-mysql-in-shell-script-but-allow-errors%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
probably you should use
run_wrapper.sh >> output.log 2>&1
â Rahul
Jul 5 '16 at 9:17
1
I'm not following. Where would you want error/warnings to go and where would you want output to go, and what would you want to throw away? What is generating the password warning and why do you have errors in the MySQL that you don't want to fix?
â Kusalananda
Jul 5 '16 at 9:38
1
mysql prints that warning when you use the
-p
option on the command line. Instead of fixing it (e.g. by creating a~/.my.cnf
with 600 perms) the OP wants to just ignore and discard the warning (and only that warning, not all of stderr)â cas
Jul 5 '16 at 13:10