HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Redirecting the output to logfile and Monitor
Operating System - HP-UX
1830895
Members
1472
Online
110017
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 08:45 AM
10-06-2005 08:45 AM
Hello All,
I have a script and i would like to have the output & errors directed to a logfile as well as the monitor.
LOGDIR=/home/log
D1=$(date "+%Y%m%d_%H%M")
exec 2>&1 | tee $LOGDIR/test.ksh.$D1
I used this comand at the begining but when a error happens it comes only in the monitor and not the logfile.
I also tried with 2>&1 at the end of the line. didt work
please help
thanks
George
I have a script and i would like to have the output & errors directed to a logfile as well as the monitor.
LOGDIR=/home/log
D1=$(date "+%Y%m%d_%H%M")
exec 2>&1 | tee $LOGDIR/test.ksh.$D1
I used this comand at the begining but when a error happens it comes only in the monitor and not the logfile.
I also tried with 2>&1 at the end of the line. didt work
please help
thanks
George
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 09:56 AM
10-06-2005 09:56 AM
Re: Redirecting the output to logfile and Monitor
I donâ t see a problem with what you have.
I tired it using something simple like the ls -l command
If you give ls -l two file names one real and one made up it sends the display of the real file to stdout (the screen) and the one that doesn't to stderr (also the screen in this case)
A single redirect arrow > redirects stdout to somewhere else and if you put >2&1 that redirects stderr to stdout and they both go where they are supposed to even if you pipe it to tee.
Is it possible that your program is not writing its error to stderr ? or what ever program is calling the script is trapping stderr before it gets to the pipe?
Try it outside your script just running the command from the command line and see how that works. It could be something about either the script or what ever your using to call the script
Wish I could help you out but it looks to me like what you have should work
H
I tired it using something simple like the ls -l command
If you give ls -l two file names one real and one made up it sends the display of the real file to stdout (the screen) and the one that doesn't to stderr (also the screen in this case)
A single redirect arrow > redirects stdout to somewhere else and if you put >2&1 that redirects stderr to stdout and they both go where they are supposed to even if you pipe it to tee.
Is it possible that your program is not writing its error to stderr ? or what ever program is calling the script is trapping stderr before it gets to the pipe?
Try it outside your script just running the command from the command line and see how that works. It could be something about either the script or what ever your using to call the script
Wish I could help you out but it looks to me like what you have should work
H
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 01:04 PM
10-06-2005 01:04 PM
Re: Redirecting the output to logfile and Monitor
I just made a small script to emulate the problem..
========================================
LOGDIR=/home/saty069/log
D1=$(date "+%Y%m%d_%H%M")
exec 2>&1 > $LOGDIR/test.ksh.$D1
case "$1" in
A ) echo "A" ;;
B ) echo "B" ;;
C ) echo "C" ;;
* ) echo "Please check the input"
exit;;
esac
echo "script still runnng"
======================================
if i give #./test T
it displays in screen nothing comes as output on screen but in the log it shows
"Please check the input"
========================================
LOGDIR=/home/saty069/log
D1=$(date "+%Y%m%d_%H%M")
exec 2>&1 > $LOGDIR/test.ksh.$D1
case "$1" in
A ) echo "A" ;;
B ) echo "B" ;;
C ) echo "C" ;;
* ) echo "Please check the input"
exit;;
esac
echo "script still runnng"
======================================
if i give #./test T
it displays in screen nothing comes as output on screen but in the log it shows
"Please check the input"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 06:06 PM
10-06-2005 06:06 PM
Solution
You have to use only the tee to redirect STDOUT and STDERR related informations to log file and console.
Example:
# cat test.sh
(
exec 2>&1;
ls muthu;
echo "script still runnning";
) | tee -a test.log
# sh test.sh
muthu not found
script still runnning
# cat test.log
muthu not found
script still runnning
muthu not found is stderror
script still runnning is stdout
hth.
Example:
# cat test.sh
(
exec 2>&1;
ls muthu;
echo "script still runnning";
) | tee -a test.log
# sh test.sh
muthu not found
script still runnning
# cat test.log
muthu not found
script still runnning
muthu not found is stderror
script still runnning is stdout
hth.
Easy to suggest when don't know about the problem!
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP