- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: File loging
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
03-06-2007 02:41 AM
03-06-2007 02:41 AM
File loging
I am looking for a way to log stdin and stderr inline from within a script and send the information to logfile and terminal without the use of the "tee" command.
ex:
exec 2>&1 1> logfile.log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 02:47 AM
03-06-2007 02:47 AM
Re: File loging
#!/usr/bin/sh
exec 1> /tmp/mylog
exec 2>&1
echo "stdout to log..."
print -u2 "stderr to log, too"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 02:52 AM
03-06-2007 02:52 AM
Re: File loging
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 02:57 AM
03-06-2007 02:57 AM
Re: File loging
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 03:02 AM
03-06-2007 03:02 AM
Re: File loging
ls 2>&1 | tee /var/tmp/outfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 03:02 AM
03-06-2007 03:02 AM
Re: File loging
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 03:02 AM
03-06-2007 03:02 AM
Re: File loging
See the tee(1) man page. (There's not much more to it than that.
You can send the stdout and stderr to the log for the entire script as follows:
#!/usr/bin/sh
(
your command in here
) | tee -a logfile
The parentheses start a subshell from which all stdout and stderr is piped to the tee command. Much easier than adding the tee command to every command that generates output in the script.
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 03:09 AM
03-06-2007 03:09 AM
Re: File loging
#!/usr/bin/sh
exec 1> /tmp/mylog
exec 2>&1
echo "stdout to log..."
print -u2 "stderr to log, too"
basically the above but needs to go to the terminal too..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 03:16 AM
03-06-2007 03:16 AM
Re: File loging
#!/usr/bin/sh
exec 1> /tmp/mylog | tee /dev/console
exec 2>&1
echo "stdout to log..."
print -u2 "stderr to log, too"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 03:38 AM
03-06-2007 03:38 AM
Re: File loging
Create a file my.sh:
----------------------------------
#!/usr/bin/sh
exec 2>&1
some_command
echo "Test Stuff"
some_opther_command
exit 0
-----------------------------------
Now when you invoke my.sh from an interactive shell or from a wrapper shell:
my.sh | tee /var/tmp/outfile
All stderr and stdout from my.sh will de directed to both the controlling terminal and to /var/tmp/outfile.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 03:47 AM
03-06-2007 03:47 AM
Re: File loging
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 04:34 AM
03-06-2007 04:34 AM
Re: File loging
I hope you can call your script more than once:
#!/usr/bin/ksh
if [ -z "$MY_SCRIPT_WRAPPER" ]
then
export MY_SCRIPT_WRAPPER=1
exec $0 2>&1 | tee /tmp/logfile
exit 0
fi
# original code here
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 05:56 AM
03-06-2007 05:56 AM
Re: File loging
#!/usr/bin/sh
NAMEDPIPE=/tmp/TDL.pipefile
mkfifo ${NAMEDPIPE}
cat ${NAMEDPIPE} | tee sample.log &
exec 1> ${NAMEDPIPE}
exec 2>&1
#Main Script
ps -ef
print -u2 "stderr to log, too"
Seems to work, anyone have any better ways?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 06:43 AM
03-06-2007 06:43 AM
Re: File loging
Have your script build a script "on the fly" either with echo's or a heredoc section and then invoke the built script and have a trap to remove the temp script file on exit. This meet's your requirement of having it all in one script. This is a common technique for doing complex operations in the shell or if you have to build awk scripts on the fly and then invoke them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 08:11 PM
03-06-2007 08:11 PM
Re: File loging
I would append something unique to the name of the pipe like
NAMEDPIPE=/tmp/TDL.pipefile.$$
Multiple instances of your script running at the same time would cause trouble otherwise.
Removing the temporary FIFO after the run of the script will prevent potential permission problems, when at later times an existing FIFO created by another user is found at runtime.
mfG Peter