I've a Java standalone program scheduled to run as cron at every 10 minutes
I want to catch/write errors thrown by this Java program both in the log file and also as a separate error file (MyJavaStandalone.err).
I know the following commands:
Errors redirected to a separate file but not to log file
/usr/java/jdk1.6.0/bin/java MyJavaStandalone >> MyJavaStandalone.log 2>> MyJavaStandalone.err &
Both log and errors are redirected to the same log file, but errors alone are not written to a separate error file
/usr/java/jdk1.6.0/bin/java MyJavaStandalone >> MyJavaStandalone.log 2>&1 &
Give this a try:
You can achieve what you want like this:
What it does:
3>&1
)2>&1
)1>MyJavaStandalone.log
)tee
takes the STDOUT of the previous command, which is actually STDERR of you Java app, appends the output to the logfile (so the logfile now has both streams) and duplicates the stream to STDOUT