LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-14-2012, 09:17 AM   #1
mmhs
Member
 
Registered: Oct 2010
Posts: 99

Rep: Reputation: 1
stderr and stdout timestamp


hi guys how can i add time stamp to stdout and stderr log file

for example i need timestamp in mylog.log
2>&1 > /var/log/mylog.log
 
Old 03-14-2012, 09:51 AM   #2
sysmicuser
Member
 
Registered: Mar 2010
Posts: 334

Rep: Reputation: 0
Did you try simple echo command like

echo "date" 2>&1 | tee -a /var/log/mylog.log?
 
Old 03-14-2012, 10:08 AM   #3
mmhs
Member
 
Registered: Oct 2010
Posts: 99

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by sysmicuser View Post
Did you try simple echo command like

echo "date" 2>&1 | tee -a /var/log/mylog.log?
didnt work i tested it before

i need timestamp for mylog.log in this example

tar -cvf /path /path 2>&1 >/var/log/mylog.log

i tested some ways however none of them work correctly

Last edited by mmhs; 03-14-2012 at 11:42 AM.
 
Old 03-15-2012, 05:25 AM   #4
sysmicuser
Member
 
Registered: Mar 2010
Posts: 334

Rep: Reputation: 0
Not sure why it doesn't work for you, it certainly works for me.

Code:
[user01@centos-flash test]$echo `date` 2>&1 | tee -a 1.log
Thu Mar 15 20:24:08 EST 2012
[user01@centos-flash test]$echo `date` 2>&1 | tee -a 1.log
[user01@centos-flash test]$cat 1.log 
Thu Mar 15 20:22:48 EST 2012
Thu Mar 15 20:24:08 EST 2012
[user01@centos-flash test]$


---------- Post added 03-15-12 at 08:26 PM ----------

You can try

set -xv on command line to see flow control of shell commands.

Please let me know how this goes...
 
Old 03-16-2012, 12:38 AM   #5
mmhs
Member
 
Registered: Oct 2010
Posts: 99

Original Poster
Rep: Reputation: 1
I think you misunderstand my question

you just send time to a file like echo `date` >> 1.log

i need a solution to attach time to my stderr and stdout log file like /var/log/messages !!!!


stderr and stdout output with time stamp

for example for this command
tar -cvf /path /path 2>&1 >/var/log/mylog.log

i need time stamp in mylog.log !!
 
Old 03-16-2012, 01:14 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
These 2 lines will create the output as ONE line in the output file : the key is the '-n' switch to echo
Code:
echo -n "`date`">t.t
ls>>t.t
One liner
Code:
(echo -n "`date`" && ls)>t.t
Or
Code:
(echo -n "`date`" ; ls)>t.t
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot redirect all stdout and stderr into file hawkgao Programming 2 05-12-2009 10:14 AM
stderr vs stdout sniffer_raghav Programming 2 09-05-2008 11:00 AM
redirecting stdout to /dev/null and stderr to stdout? Thinking Programming 1 05-18-2006 03:36 AM
redirecting stdout and stderr to a file Avatar33 Programming 4 03-12-2005 08:55 AM
Reopen the stdout and stderr rahul_kulkarni Programming 3 02-21-2005 07:55 AM


All times are GMT -5. The time now is 05:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration