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" |
Will "script" do what you want? http://man7.org/linux/man-pages/man1/script.1.html
|
Quote:
|
Example usage:
Code:
$ cat myscript.sh Code:
$ cat output.log |
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 |
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.
|
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. |
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 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. |
Quote:
|
It would be helpful if you could post a simple (e.g. 1 or 2 questions/inputs) script that exhibits the same problem.
|
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/ |
All times are GMT -5. The time now is 03:35 PM. |