Capturing errors messages into log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Capturing errors messages into log file
# 1  
Old 05-19-2011
Capturing errors messages into log file

Can we capture and write all the error messages which were being displayed on the command prompt screen during execution of a program into a log file?

If yes, can anyone please let me know on how to do it?

I am using ksh and working on AIX server.

Thank you in advance.
# 2  
Old 05-19-2011
# 3  
Old 05-19-2011
Thank you Franklin.

I understood that by writing the script as below, we can capture stdout and stderr to a file.
Code:
 ./program.ksh >> /home/log.txt 2>> /home/log.txt

Instead how to get the same functionality by writting something similar inside the program so that if we just run the script it should capture stderr and stdout to a file.

so now i will execute the script as
Code:
./program.ksh

and it should do the same functionality by writting the stderr and stdout to the fiile log.txt.
# 4  
Old 05-19-2011
try this. funny what you find with a internet search.
https://www.unix.com/shell-programmin...ithin-ksh.html
# 5  
Old 05-20-2011
This works for ksh but not for all other Shells. We run everything in a subshell defined by a pair of brackets.

Code:
#!/bin/ksh
(

#my commands go here

) 1>>/home/log.txt 2>>/home/log.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Outputting Errors to a Log file

Good Morning, Every so often, I have copy scripts that to don't complete, but I don't immediately know why. It usually ends up being a permissions issue or a length issue. The scripts edit a log file, so I'd like to include any copy errors/issues in that file to check if the copies... (4 Replies)
Discussion started by: Stellaman1977
4 Replies

2. UNIX for Beginners Questions & Answers

Need in for a script that should check for errors in multiple log file (approx 2500) and should mail

hello everyone, I am new to linux and got this deliverable to write a script that should check for error in multiple log file (count is approx 2500 log files on single server) and once error is found, it should mail that error My logic says: we can put all log files path/location in one... (2 Replies)
Discussion started by: Pratik_CTS
2 Replies

3. Shell Programming and Scripting

Scan log file for errors

Hi everyone. I am still new to UNIX, and am having trouble figuring out how to create a script to scan a log file to look for errors based on a string. We run AIX 5.3, and would like the ability to report all the instances of WebSphere Broker Execution groups crashing. This script would... (8 Replies)
Discussion started by: jimbojames
8 Replies

4. Shell Programming and Scripting

Finding errors in log file only in last 10 minutes

Hi there, I have a log file that I need to check every 10 minutes to find if a specific error exists but only in that 10 minute period. The reason is that the log is quite large, and will frequently contain these errors, so I only want alerting if it in the last 10 minutes - I don't want... (3 Replies)
Discussion started by: paul_vf
3 Replies

5. Red Hat

Help for capturing a URL from a line from large log file

Can someone please help me how do I find a URL from lines of log file and write all the output to a new file? For e.g - Log file has similar entries, 39.155.67.5 - - "GET /abc/login?service=http://161.120.36.39/CORPHR/TMA2007/default.asp HTTP/1.1" 401 3218 54.155.63.9 - - "GET... (2 Replies)
Discussion started by: rockf1bull
2 Replies

6. Shell Programming and Scripting

track the errors in log file

OS: SuSE Linux Enterprise Server 10 Goal: To track the errors in log file, If they exits users will be notify by email. We have a script below: SrchKey="SRVE0242I:" LogFile=/PATHtemOut.log MailTo="DN@mail.com http:// ! -f PATH/alert.last && touch PATH/alert.last egrep $SrchKey $LogFile... (3 Replies)
Discussion started by: sdhn1900
3 Replies

7. Solaris

NFS errors on messages file.

Hi, The following messages are getting logged to messages file extensively while the omniback backup is going on "NFS write error on host test.test.com: Read-only file system." The system has nfs filesystems and we are backing it up at that time. Any thoughts ?... Appreciate it..... (8 Replies)
Discussion started by: amqstam
8 Replies

8. Shell Programming and Scripting

prevent errors/warnings from being written to log file

i have this script which works fine but shows errors when it runs..these are more like warnings and the script runs fine.. i am on a sun machine.. i know it writes all the error messages to a master log file.. is there any way i can turn off these warnings/error messages and prevent them from being... (2 Replies)
Discussion started by: npatwardhan
2 Replies

9. Shell Programming and Scripting

redirect errors to log file

I am working on a generic script that will run a shell script with the arguments passed and redirect errors to one file, and all other output to another file. Then if there is anything in the error file it emails the error to me, otherwise it exits. The advantage for this approach is that I... (0 Replies)
Discussion started by: gandolf989
0 Replies

10. Linux

NFS throwing errors in /var/log/messages

Jan 2 19:49:25 lab009 last message repeated 2 times Jan 2 19:49:25 lab009 kernel: RPC call_verify: retry failed, exit EIO Jan 2 19:49:25 lab009 kernel: call_verify: server accept status: 5 Jan 2 19:49:25 lab009 last message repeated 2 times Jan 2 19:49:25 lab009 kernel: RPC call_verify:... (1 Reply)
Discussion started by: Sivaswami
1 Replies
Login or Register to Ask a Question