LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-30-2010, 07:01 AM   #31
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Original Poster
Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192

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.

Any help greatly appreciated
 
Old 08-30-2010, 10:29 AM   #32
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Hi,

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?
 
Old 08-30-2010, 11:07 AM   #33
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Original Poster
Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Hey crts

Quote:
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
 
Old 08-30-2010, 11:51 AM   #34
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Code:
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.
 
Old 08-31-2010, 04:57 AM   #35
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
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

Code:
>&3 2>&4 make menuconfig
 
Old 10-12-2010, 05:21 AM   #36
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Original Poster
Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Howdy all

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
}
 
Old 10-14-2010, 04:29 AM   #37
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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"
 
1 members found this post helpful.
Old 10-14-2010, 05:19 AM   #38
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Original Poster
Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
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
The correct data is being stored in the file.

Any thoughts?
 
Old 10-15-2010, 01:20 AM   #39
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Original Poster
Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
As you can see above, the following works:
Code:
echo back to normal stdout >&"$FD"
But apparently doing the same process with the variable at the front does not seem to work:
Code:
FD=3;exec "$FD">&1
When I run this i get the following error:
Code:
/.d.sh: line 6: exec: 3: not found
Anyone have any ways to get around this?
 
Old 10-15-2010, 01:45 AM   #40
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
with that there's really no choice but to use eval

Code:
eval "exec $FD>&1"
assuming:
Code:
shopt -s extglob
[[ $FD == +([[:digit:]]) ]]
 
Old 10-15-2010, 01:51 AM   #41
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Original Poster
Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Well I was trying to get away from eval if possible, but it seems appropriate here

Any ideas on post #38?
 
Old 10-21-2010, 02:31 AM   #42
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
the one inside the function is probably already using a different handle so it's already a bit delayed.

tee is in a different pipe so that could also be delayed

Last edited by konsolebox; 10-21-2010 at 02:41 AM.
 
  


Reply



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
Scripting the kernel compile easuter Linux - Kernel 2 06-29-2007 07:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:32 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