Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-26-2014, 05:08 AM
|
#1
|
Member
Registered: Aug 2009
Posts: 539
Rep:
|
How to add timestamp to the output string?
Hi,
I have a script which calls a java program as follow:
...
exec 5 > /var/log/mylog.log
...
java -cp $CLASSPATH -Xms64m -Xmx512m $JAVA_OPTS $MAINCLASS >&5 2>&1
...
The problem is, there is no any timestamp writen into the log file. How can I add the timestamp?
|
|
|
05-26-2014, 05:39 AM
|
#2
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,502
|
for example:
date >> /var/log/mylog.log
and you need to use >> instead of single >
java -cp $CLASSPATH -Xms64m -Xmx512m $JAVA_OPTS $MAINCLASS >>&5 2>&1
|
|
|
05-26-2014, 05:59 AM
|
#3
|
Member
Registered: Aug 2009
Posts: 539
Original Poster
Rep:
|
Hi,
As I use the
Code:
...
java -cp $CLASSPATH -Xms64m -Xmx512m $JAVA_OPTS $MAINCLASS >>&5 2>&1
...
I got error message:
Code:
...
./myscript.sh: line 92: syntax error near unexpected token `&'
./myscript.sh: line 92: `java -cp $CLASSPATH -Xms64m -Xmx512m $JAVA_OPTS $MAINCLASS >>&5 2>&1'
...
|
|
|
05-26-2014, 06:10 AM
|
#4
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,502
|
so you need a filename:
Code:
logfilename=/var/log/mylog.log
date >> $logfilename
java -cp ..... >>$logfilename 2>&1
|
|
|
05-26-2014, 07:54 AM
|
#5
|
Member
Registered: Aug 2009
Posts: 539
Original Poster
Rep:
|
Hi,
This works.
But how can I print the mini-second as weill?
|
|
|
05-26-2014, 08:03 AM
|
#6
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,502
|
see man date, probably date '+%D %T.%N' >> $logfilename works for you
|
|
|
05-26-2014, 02:10 PM
|
#7
|
Senior Member
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,992
|
Quote:
Originally Posted by thomas2004ch
Hi,
This works.
But how can I print the mini-second as weill?
|
man date or date --help to get the syntax for the date command. powerful tool the date command.
|
|
|
All times are GMT -5. The time now is 07:25 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|