ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hmmmm ... So I finally had a chance to try my new version of logging. Unfortunately i seem to have come full circle
In fact I have since discovered that my original intention of trying to run 'make menuconfig' when not tee'ed (ie directed at logfile) is now
unable to be seen at all, which makes sense as both stdout and stderr are now going to logfile.
So it would appear I somehow need to tell my script that when this line, 'make menuconfig', appears that it should somehow break out of
its logging mode.
Any suggestions?
Here is a loose picture of how the call goes:
1. call package manager with install option and the name 'linux'
2. After some checks are done the script submits the following:
Code:
su - linux -c "scribe"
This will start the setup and install process. Basically as soon as the script enters here it will start logging output.
3. (this will be for simplicity of what we are trying to do in this instance) Extract source and change into directory created
4. Source a file that has all the related commands for this install including our issue command:
Code:
make menuconfig
So at this point is where I somehow need to tell the scribe script to suspend its logging until the completion of this command.
I am not sure what your actually goal is right now.
Quote:
In fact I have since discovered that my original intention of trying to run 'make menuconfig' when not tee'ed (ie directed at logfile) is now
unable to be seen at all, which makes sense as both stdout and stderr are now going to logfile.
I thought that the command works if the redirection is made by use of file descriptors. So when you want to catch the 'menuconfig' you do not have to suspend tee logging at all. However, catching this output will not result in something like a 'slideshow' where you can trace each step that you made.
So when you stop redirecting to tee, then where exactly is the problem to restore stdout? Basically, that would be my suggestion from post #6.
Code:
su - linux -c "scribe"
Am I assuming right that this is your package user to install the kernel, i.e. if you want to install gcc you'd issue
Code:
su - gcc -c "scribe"
So 'linux' is not some special install user that handles the installation of all packages, right?
Am I assuming right that this is your package user to install the kernel, i.e. if you want to install gcc you'd issue
100% correct. Each application is installed as the user name associated with it.
Quote:
I thought that the command works if the redirection is made by use of file descriptors.
There was a state where it worked which was:
Code:
exec 3>&1 4>&2
exec 2>&1
(
make menuconfig
) | tee logfile
exec >&3 2>&4 3>&- 4>&-
sleep 1
echo after log
This seems to work just fine, although you were correct in a previous post where it fills the log with all kind of weird characters due to the dialog.
Of course this has raised the previously identified issue that should I remove the tee altogether then the dialog is completely hidden due to the redirection.
So I do need to somehow catch when an install will require this type of interaction and somehow suspend the logging until such a time that it is closed
and the logging can resume.
Definately starting to feel like one of those scenarios where I might have bitten off a little more than I can chew
exec 3>&1 4>&2 # start logging
exec 2>&1
(
... stuff you want to log
) | tee -a logfile
exec >&3 2>&4 3>&- 4>&- # stop logging
sleep 1
(
make menuconfig
) 2>>logfile # log only stderr
exec 3>&1 4>&2 # start logging
exec 2>&1
sleep 1
(
... more stuff that you want logged
) | tee -a logfile
A slight variation of post #6. (UNTESTED)
Quote:
So I do need to somehow catch when an install will require this type of interaction and somehow suspend the logging until such a time that it is closed and the logging can resume.
Do you mean that you do not want to make any changes in the sourced command script? Do you want 'linux' script to auto detect the necessity of redirection? I am not sure if this can be done with the tools that we have at hand in our toolchain - or at all.
Please clarify if I understood you correctly.
So it would appear I somehow need to tell my script that when this line, 'make menuconfig', appears that it should somehow break out of
its logging mode.
Perhaps you just need to redirect menuconfig to &3 and &4
Sorry I left this one for so long ... got side tracked.
I think I have my working solution now but I just wanted to ask one more questions (although I think I already know the answer).
Let us assume I have done the following:
Code:
exec 3>&1 4>&2
exec &> >(exec tee logfile)
echo good
edho bad
exec >&3 2>&4 3>&- 4>&-
sleep 1
<do other stuff>
Now I want to call another user function in between 'good' and 'bad' lines. My question is it possible to pass the file descriptor or its number to the function
so that in the function I can use a variable for the redirection?
Code:
echo good
my_func <fd reference here>
edho bad
# function description from another file
my_func()
{
local FD=$1
echo back to normal stdout >&$FD # I realise this does not work so it is just to illustrate what I am trying to do
}
I seem to have used that method in my scripts and it worked.. maybe try to put it in quotes:
Code:
# echo back to normal stdout >&$FD # I realise this does not work so it is just to illustrate what I am trying to do
echo back to normal stdout >&"$FD"
Thanks heaps konsolebox ... not sure why I didn't think to try that
Do you have any thoughts as to why the output from my function to stdout is being processed prior to the echo in the script?
Script being run is:
Code:
#!/bin/bash
# function description from another file
my_func()
{
local FD=$1
echo back to normal stdout >&"$FD" # I realise this does not work so it is just to illustrate what I am trying to do
}
exec 3>&1 4>&2
exec &> >(exec tee testlogfile)
echo good
my_func 3
edho bad
exec >&3 2>&4 3>&- 4>&-
sleep 1
echo after all said and done
So from this I would have expected the following output based on where the echoes are:
Quote:
good
back to normal stdout
./d3.sh: line 16: edho: command not found
after all said and done
And yet the actual output is:
Quote:
back to normal stdout
good
./d3.sh: line 16: edho: command not found
after all said and done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.