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 05-29-2017, 03:22 PM   #1
DexterMorgan
LQ Newbie
 
Registered: Apr 2015
Posts: 13

Rep: Reputation: Disabled
Running a script with |tee myLogfile.log causes problems


Hi,

So I have a custom script for installation of my MySQL database that I'm running with tee to be able to go back and study it in case of something happens.

When the database is installed and the script is executing:

sudo /usr/bin/mysql_secure_installation

it asks my for my password, and then nothing happens. I know that I'm supposed to get questions like:

Remove anonymous users?
Disallow root login remotely?
Remove test database and access to it?
Reload privilege tables now?

But I'm left with nothing. If I press enter a bunch of times the I suddenly see a screen with all these questions already answered - when I pressed enter a couple of times I must've given it the default answer.

I'm executing the script as root:
./myScript.sh 2>errors.log | tee installation_history.log

How do I solve this so I get to answer the questions and save history to the logfile "installation_history.log"
 
Old 05-29-2017, 06:36 PM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Will "script" do what you want? http://man7.org/linux/man-pages/man1/script.1.html
 
Old 05-29-2017, 07:05 PM   #3
DexterMorgan
LQ Newbie
 
Registered: Apr 2015
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by norobro View Post
I'm not following, can you elaborate on this? an example?

Last edited by DexterMorgan; 05-29-2017 at 07:10 PM.
 
Old 05-29-2017, 07:18 PM   #4
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Example usage:
Code:
$ cat myscript.sh
#!/bin/bash

script -c mysql_secure_installation output.log
Run myscript (./myscipt.sh) and answer questions.

Code:
$ cat output.log
Script started on Mon 29 May 2017 07:15:11 PM CDT

Securing the MySQL server deployment.


VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: n
Using existing password for user.
Change the password for user ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : n

 ... skipping.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
All done! 

Script done on Mon 29 May 2017 07:15:15 PM CDT

Last edited by norobro; 05-30-2017 at 08:44 AM.
 
Old 05-29-2017, 08:37 PM   #5
r.stiltskin
Member
 
Registered: Oct 2003
Location: USA
Distribution: Xubuntu, Arch
Posts: 231

Rep: Reputation: 31
If mysql_secure_installation isn't writing anything to stdout, there isn't anything for tee (or script) to send to a file. So you'll have to look at your script itself to see why it isn't doing what you expected. Maybe running it step by step (with the bash -x option) will help, e.g.

Code:
sudo bash -x /usr/bin/mysql_secure_installation
 
Old 05-29-2017, 10:00 PM   #6
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
Maybe all of the prompts are being written to stderr, so sending 2 aka stderr aka /dev/stderr to >error.log leaves nothing for tee to get on stdout aka 1 aka /dev/stdout. Just a guess, using 2>&1 | tee might better suit, or at least one thing to try in the absence of other things.
 
Old 06-04-2017, 12:20 AM   #7
DexterMorgan
LQ Newbie
 
Registered: Apr 2015
Posts: 13

Original Poster
Rep: Reputation: Disabled
So, I've tested out what you guys suggested, but neither was working the way I was expecting, so I'm back to square one,

so the pipe | tee mySavedHistory.log is causing all problems, but I still want the oppertunity to go back and check the log. Any more ideas?

And why do you think the pipe is cauasing this problem?
what does the pipe do exaktly?

and about 2>error.log
nothing of interest is showing up here, so I haven't the foggiest idea where the missing questions from /usr/bin/mysql_secure_installation is ending up, right now a black hole it seems.

Last edited by DexterMorgan; 06-04-2017 at 12:24 AM.
 
Old 06-04-2017, 12:23 PM   #8
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
The pipe basically takes the output of one thing and sends it to the input of other thing. Using tee lets you copy the flow of data to a file while sending it along. There's a caveat that the thing receiving the pipe actually takes input. Specifically from stdout.

Some basics:

0 stdin /dev/stdin
1 stdout /dev/stdout
2 stderr /dev/stderr

A practical demonstration:

FILE: bashtest.sh
Code:
#!/bin/bash

echo "some thing to stdout"
echo "some thing to stderr" >&2
echo "some thing else to stdout"
echo "some thing else to stderr" >&2

exit 0
$ bash bashtest.sh
some thing to stdout
some thing to stderr
some thing else to stdout
some thing else to stderr

$ bash bashtest.sh 2> tempSTDERR.txt
some thing to stdout
some thing else to stdout
$ cat tempSTDERR.txt
some thing to stderr
some thing else to stderr


$ bash bashtest.sh > tempSTDOUT.txt
some thing to stderr
some thing else to stderr
$ cat tempSTDOUT.txt
some thing to stdout
some thing else to stdout

$ bash bashtest.sh 2>&1 | > tempALL.txt
$ cat tempALL.txt

$ bash bashtest.sh 2>&1 | cat - > tempALL.txt
$ cat tempALL.txt
some thing to stdout
some thing to stderr
some thing else to stdout
some thing else to stderr

$ bash bashtest.sh 2>&1 | tee tempALL.txt
some thing to stdout
some thing to stderr
some thing else to stdout
some thing else to stderr
$ cat tempALL.txt
some thing to stdout
some thing to stderr
some thing else to stdout
some thing else to stderr

$ rm tempSTDERR.txt tempSTDOUT.txt tempALL.txt

$ bash bashtest.sh 2> tempSTDERR.txt > tempSTDOUT.txt
$ cat tempSTDERR.txt
some thing to stderr
some thing else to stderr
$ cat tempSTDOUT.txt
some thing to stdout
some thing else to stdout
$ cat tempALL.txt
cat: tempALL.txt: No such file or directory

Sometimes it's simpler to make a stupid test case like these to figure it out before modding/debugging the more complex monstrosity.

Last edited by Shadow_7; 06-04-2017 at 12:24 PM.
 
Old 06-05-2017, 07:28 AM   #9
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by DexterMorgan View Post
I'm executing the script as root:
./myScript.sh 2>errors.log | tee installation_history.log
Then why is sudo necessary in it?
 
Old 06-06-2017, 07:10 AM   #10
r.stiltskin
Member
 
Registered: Oct 2003
Location: USA
Distribution: Xubuntu, Arch
Posts: 231

Rep: Reputation: 31
It would be helpful if you could post a simple (e.g. 1 or 2 questions/inputs) script that exhibits the same problem.
 
Old 06-06-2017, 10:22 AM   #11
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Give this page a read: http://www.pixelbeat.org/programming/stdio_buffering/

The section "stdio buffer control", near the bottom of the page, describes how to use the command "stdbuff".

Putting "stdbuf -oL mysql_secure_installation" in the script or putting "stdbuf -oL" first on the command line worked on my machine.

Possibly of interest:
https://bugs.mysql.com/bug.php?id=53796
http://bertvv.github.io/notes-to-sel..._installation/
 
  


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
How to write a log file of a user interactive process using tee. ira Linux - Newbie 2 10-01-2010 03:55 AM
How to create Log of what running script does?? linus72 Linux - General 16 12-17-2009 10:28 AM
Running Dansguradian: access.log problems ct2k7 Linux - Newbie 4 12-22-2008 10:43 AM
Running Shell Script at log in. ceantuco Programming 21 11-05-2008 02:56 PM
How to create a log File using tee?? rmvinodh123 Programming 1 04-12-2007 02:21 AM

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

All times are GMT -5. The time now is 10:43 PM.

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