- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script logging
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
10-24-2001 02:25 AM
10-24-2001 02:25 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2001 02:37 AM
10-24-2001 02:37 AM
Re: Script logging
Can you not redirect the script's output when you run it, e.g.
./my_script.sh >log.out 2>&1
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2001 02:37 AM
10-24-2001 02:37 AM
Re: Script logging
Try this:
----------------------------
#!/bin/sh
LOG=/tmp/mylog
your_original_script()
{
...your script...
}
your_original_script >> $LOG 2>&1
----------------------------
Cheers,
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2001 02:39 AM
10-24-2001 02:39 AM
Re: Script logging
Yep, run script like:
<script> 1>normal_log 2>error_log
E.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2001 02:59 AM
10-24-2001 02:59 AM
Solutionexec 2>&1 >${Logfile}
But, as most shell scripts are run both as batch and by the admin I'd advise using a system that sends output to both the Logfile and stdout - the normal way of doing this is to do summat like:
echo "foo" 2>&1 | tee -a ${Logfile}
This has 2 problems:
* increases size of script
* loses return code of the command before the tee...
What I do is have a function which runs a command, handles the logging and returns the valid return code [it also adds date time and program name to the logfile]:
function LogExec
{
typeset Status
typeset TempFile=$(mktemp)
${@} 2>&1 >${TempFile}
Status=${?}
while read line
do
print "[${1##*/}] $(date "+%Y%m%d %H:%M:%S") ${line}" | tee -a ${LogFile}
done <${TempFile}
rm -f ${TempFile}
return ${Status}
}
So when you have this you just need to do the following:
LogExec rm foo*
instead of
rm foo* | tee -a ${LogFile}
dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2001 03:00 AM
10-24-2001 03:00 AM
Re: Script logging
man script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2001 03:43 AM
10-24-2001 03:43 AM
Re: Script logging
I tried the script command but found this the best solution.
#!/usr/bin/sh
exec > $log 2>&1
Thanks for the tips.
Malcolm