bash scripts creating log files
Hi, everyone.
I'm trying to write a bash script which is basically a wrapper around a number of other commands.
What I _want_ to do is basically _copy_ stdout and stderr to a log file.
Thus, when I run a command, I wans the stdout and stderr to go to wherever called the script (eg an interactive terminal) but I _also_ want it to go to a log file.
I can do it easily for things I'm echoing in my own script by writing a function like this:
function ECHO
{
echo $1
echo $1 >> ${Logfile}
}and then any messages which I generate I use ECHO instead of echo:
ECHO "This is a message"
What I can't figure out is how do I redirect the output of the things I'm running to the same 2 places?
Anyone know a nice easy way to do this?
Tnx.
Paul.
Signature · 11 lines
Paul Furness Systems Manager 2+2=5 for extremely large values of 2. - To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.linux-learn.org/faqs
Exporting display
Hi Everyone,
I connect to a Linux machine using SSH from a Windows NT workstation and need to bring up graphical programs on my console. I find that I am unable to do this... Could anyone please tell me what I should do?
Here's what I did...
1. Run XWin on my workstation. This shows up on my system tray
2. Execute "setenv DISPLAY ${REMOTEHOST}:0.0" after connecting to my linux machine through SSH
3. echo $REMOTEHOST gives me hughes08.biac.duke.edu (my Windows NT workstation)
4. echo $DISPLAY gives me hughes08.biac.duke.edu:0.0
However, when I type xbiff& after connecting to my linux machine, I just get the process ID. The xbiff window does not show up!
Regards,
Abhijit.
__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Quoted 16 lines · Paul Furness
What I _want_ to do is basically _copy_ stdout and stderr to a log file.
Thus, when I run a command, I wans the stdout and stderr to go to wherever called the script (eg an interactive terminal) but I _also_ want it to go to a log file.
I can do it easily for things I'm echoing in my own script by writing a function like this:
function ECHO { echo $1 echo $1 >> ${Logfile} }
Quoted 6 lines
and then any messages which I generate I use ECHO instead of echo:
ECHO "This is a message"
What I can't figure out is how do I redirect the output of the things I'm running to the same 2 places?
"tee" is your friend:
echo test | tee -a logfile.txt
test is printed to the screen and appended to the file "logfile.txt". If you don't use the "-a" the file is overwritten every time.
HTH
--
Jos Lemmerling on Debian GNU/Linux jos(@)lemmerling(.net)
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Quoted 21 lines · Paul Furness
Hi, everyone.
I'm trying to write a bash script which is basically a wrapper around a number of other commands.
What I _want_ to do is basically _copy_ stdout and stderr to a log file.
Thus, when I run a command, I wans the stdout and stderr to go to wherever called the script (eg an interactive terminal) but I _also_ want it to go to a log file.
I can do it easily for things I'm echoing in my own script by writing a function like this:
function ECHO { echo $1 echo $1 >> ${Logfile} }
Quoted 6 lines
and then any messages which I generate I use ECHO instead of echo:
ECHO "This is a message"
What I can't figure out is how do I redirect the output of the things I'm running to the same 2 places?
There is a command called "tee" which will pipe data to a file and stdout/stderr at the same time
you do:
someprog | tee /tmp/some.log.file
The output of someprog is sent to stdout/stderr and the file /tmp/some.log.file
You can then do what you like with stdout/stderr as normal.
tee should be installed as it comes with sh-utils package.
--
Carl
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Everyone,
Thanks for your help. Tee is exactly what I needed, and works perfectly.
P.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Re: Exporting display
In reply to Abhijit VijayQuoted 4 lines · Abhijit Vijay
2. Execute "setenv DISPLAY ${REMOTEHOST}:0.0" after connecting to my linux machine through SSH
Quoted 9 lines
3. echo $REMOTEHOST gives me hughes08.biac.duke.edu (my Windows NT workstation)
4. echo $DISPLAY gives me hughes08.biac.duke.edu:0.0
However, when I type xbiff& after connecting to my linux machine, I just get the process ID. The xbiff window does not show up!
Abhijit,
Did you try running it in the foreground first (without the
'&')? Some applications require a terminal to work atleast during initialization and putting it in background mode may just stop the process. The other thing to check for is whether your .xsession-errors file shows any error messages. If it shows access denied type messages, perhap you need to run xhost or an equivalent program on your NT machine.
Regards,
Kenneth
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs