The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 07-01-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,121
Quote:
Originally Posted by pravfraz View Post
hi folks,

In the following code, logfile remains empty.
Code:
 
log_file="/u/Sc/prav.log.$mon$day"
 
ps -ef | grep "myprocess"| awk -v logfile=$log_file '{
 system("date >> logfile")
}'
can u please help as how to log the date to that logfile.
thanks in advance!
  1. why do you need awk? Cannot you use file redirection instead?
  2. If you do need awk, why do you need 'grep'? Awk can do it all.
  3. ps -ef | awk -v logfile="${log_file}" '/myprocess/{cmd="date >> " logfile; system(cmd); close(cmd)}"