Register
It is currently Mon Sep 01, 2014 10:16 pm

create a logfile with current date deom .bash_profile


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Tue Aug 03, 2010 5:37 am   

Joined: Tue Aug 03, 2010 5:31 am
Posts: 3
Hi Mentors,

Here is what i intend to do in the .bash_profile
alias build_myproject="make -j4 2>&1 | tee log_`date +%a_%d_%b_%H_%M%p`.log"
I wanted to give the command "build_myproject" in the shell and i expect a logfile with the current time.

I understand that the .bash_profile is executed when the remote shell starts and the `date +%a_%d_%b_%H_%M%p` is replaced by the time at the moment.
How do i tell bash not to execute `date +%a_%d_%b_%H_%M%p` through .bash_profile?

If somebody already using for a similar purpose provide me the script or anything that can do this job.

Thanks
Bujji


Top
 Profile  
 PostPosted: Tue Aug 03, 2010 1:08 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
You can do this by escaping the backticks/backquotes that encompase your date command.
This way, they will be taken as a litteral in your alias, but will be evaluated when executing the alias.


Top
 Profile  
 PostPosted: Tue Aug 03, 2010 7:10 pm   

Joined: Tue Aug 03, 2010 5:31 am
Posts: 3
Thanks for the suggestion. Here is what i see

alias build_myproject="make -j4 2>&1 | tee log_date +%a_%d_%b_%H_%M%p.log"
The above resulted in creating a logfile +%a_%d_%b_%H_%M%p.log

alias build_myproject="make -j4 2>&1 | tee log_date+%a_%d_%b_%H_%M%p.log" (removed space between date and +)
This resulted in creating a log file log_date+%a_%d_%b_%H_%M%p.log


Top
 Profile  
 PostPosted: Wed Aug 04, 2010 2:02 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Why did you remove the backticks/backquotes? I suggested to escape them, not remove them.


Top
 Profile  
 PostPosted: Wed Aug 04, 2010 5:14 pm   

Joined: Tue Aug 03, 2010 5:31 am
Posts: 3
My BAD.
Thanks man . This is what i am looking for.


Top
 Profile  
 PostPosted: Thu Aug 05, 2010 4:21 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
one could also create a function rather than an alias

Code:
function build_myproject {
  make -j4 2>&1 | tee "log_$(date +%a_%d_%b_%H_%M%p).log"
}


Top
 Profile  
 PostPosted: Fri Aug 06, 2010 8:27 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 666
Location: Des Moines, Iowa
DarthWavy wrote:
one could also create a function rather than an alias

Code:
function build_myproject {
  make -j4 2>&1 | tee "log_$(date +%a_%d_%b_%H_%M%p).log"
}


+1 :)


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP