- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How do you capture all terminal output resulting f...
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
Discussions
Discussions
Forums
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
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
тАО05-23-2002 05:44 AM
тАО05-23-2002 05:44 AM
One way I know I could do this is to use "tee" to write both to the terminal and to a log file. However, the scripting style I want to use is to call functions within an "if" statement. The functions will return 0 if successful, and non-zero if it is unsuccessful... similar to the following code.
if SomeFunction; then
State=/bin/true
else
State=/bin/false
fi
If I were to include a "| tee -a ${OutputFile}", it will skew the return code value of the function, and will always be true if the "tee" command is successful.
I could use tee in a pipeline when the script is initiated. I could also use the "script" command to capture it as well, but then every user would have to remember to invoke the script in one of these 2 ways... which wouldn't happen.
I tried putting the "script" command within the script, but as the man page says, I just get a spawned shell, and the script then proceeds after I exit the spawned shell... not capturing the output as I intend.
A good example of what I am trying to accomplish is the way the swintall command operates in non-interactive mode. All the terminal I/O is displayed to the user, and also captured in a file in the /var/adm/sw/ directory.
I'm looking to direct STDERR and STDOUT for the entire script, not individual commands, and to somehow do it within the script itself.
Any ideas would be appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2002 05:47 AM
тАО05-23-2002 05:47 AM
Re: How do you capture all terminal output resulting from running a script?
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x6ac253921f1ad5118fef0090279cd0f9,00.html
GL,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2002 05:48 AM
тАО05-23-2002 05:48 AM
Re: How do you capture all terminal output resulting from running a script?
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2002 05:52 AM
тАО05-23-2002 05:52 AM
Re: How do you capture all terminal output resulting from running a script?
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2002 05:53 AM
тАО05-23-2002 05:53 AM
Re: How do you capture all terminal output resulting from running a script?
Try using a video/screen capture device using an xterm. You could voice over with the 'why', while the trainee see the commands being entered.
I know it seems a bit hollywood, but I've used many such training materials, and the trainees really benefit from the commentary and the examples.
Good Luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2002 05:55 AM
тАО05-23-2002 05:55 AM
Re: How do you capture all terminal output resulting from running a script?
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2002 05:56 AM
тАО05-23-2002 05:56 AM
Re: How do you capture all terminal output resulting from running a script?
I think you are trying to capture the std output and the std err that gets displayed on the terminal when the script is run. Try this,
sh script >script.run.log 2>&1
or
./script >script.run.log 2>&1
Hope this helps.
regds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2002 06:01 AM
тАО05-23-2002 06:01 AM
Re: How do you capture all terminal output resulting from running a script?
If you don't want all the trace statements, then you'll be best off writing a separate function for displaying all messages. So instead of writing:
echo "Enter new data: \c"
you would use (assumes $LOGFILE has already been defined):
LogWrite "Enter new data: \c"
and write a function like:
function LogWrite
{
print "$@" | tee -a $LOGFILE
}
And to capture non-zero exit codes seen by the shell put this trap statement at the beginning:
trap 'ErrWrite $0: A non-zero returncode occurred at line $LINENO' ERR
This trap statement will add the name of the script and the line number where any error return was detected. You may want to tee the error output into a different file such as $ERRLOG. The function ErrWrite would be:
function ErrWrite
{
print "$@" | tee -a $ERRLOG
}
For calls to processes that may return STDERR, you'll have to add: 2>>$LOGFILE (or 2>>$ERRLOG) to the end of each process call.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2002 06:03 AM
тАО05-23-2002 06:03 AM
Re: How do you capture all terminal output resulting from running a script?
As shown
script /tmp/file
Prompt will return
script
At end of script
exit
Prompt will return
All output to the screen is in /tmp/file
To debug the script if needed put set -x as
the first non comment line and all commands are also echoed as they are executed
steve steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2002 10:31 AM
тАО05-23-2002 10:31 AM
Re: How do you capture all terminal output resulting from running a script?
While I didn't use any of the ideas exclusively, I got a different idea from them, and thought I would share my solution:
Here's the code I put in the first part of the Main section of my script after all my function declarations:
: ${ScriptLog:="/tmp/${0##*/}.log"}; export ScriptLog
: ${FirstTimeThru:=/bin/true}; export FirstTimeThru
if ${FirstTimeThru}; then
test -f "${ScriptLog} && /usr/bin/mv ${ScriptLog} ${ScriptLog}.old || > ${ScriptLog}
export FirstTimeThru="/bin/false"
${0} $@ 2>&1 | tee -a ${ScriptLog}
else
exit $?
fi
I've tested this logic, and it gives me exactly what I was looking for. Thanks for all the suggestions!!!