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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep using date format ali560045 Shell Programming and Scripting 4 12-26-2007 08:59 AM
date issue-find prevoius date in a patricular format bsandeep_80 UNIX for Advanced & Expert Users 3 11-15-2007 08:42 PM
convert mmddyy date format to ccyyddd format?? Bhups Shell Programming and Scripting 2 09-27-2006 11:30 PM
Date format: Khoomfire UNIX for Advanced & Expert Users 1 02-13-2006 09:44 AM
date format big123456 Shell Programming and Scripting 2 07-22-2005 04:57 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-07-2007
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
grep using date format

i have a process ruuning

root 843786 835648 0 Nov 10 - 0:31 java
root 860340 1 0 Nov 11 - 0:31

then how to grep this using date above

i have written a script
----------------------------
#!/bin/ksh

a=`date +"%m-%d"`
ps | grep root | grep "$a" >> file1
------------------------------------------------

but not getting anything in file1,
plz tell me how to grep this process using the above date and put in file1
  #2 (permalink)  
Old 12-07-2007
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,912
Try

Code:
a=`date +"%b-%d"`
%m returns the month number not the abreviated month name
  #3 (permalink)  
Old 12-08-2007
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
still not gettin the contents in file "dates"

-------------------------------------------------------------

#!/bin/ksh

a=`date +"%b-%d"`
ps | grep root | grep $a >> dates
--------------------------------------------------------------
these are the process :

root 3694688 7503998 0 Nov 03 - 0:12 /usr/bin/iostat -d 30
root 7200814 7503998 0 Nov 03 - 0:08 ./ifstat 30 10
root 7209086 1 0 Jun 14 - 4:20 /usr/sbin/cron
root 7503998 3117144 0 Nov 03 - 1:11 ./stat_daemon 9
root 7663756 7503998 0 Nov 03 - 2:10 ./nfs_stat AIX 30

----------------------------------------------------------------------
can u tell me how to grep the process acording to the above dates .
Actually i m able to create the file "dates" but its empty.............
i think some problem lies in my script in

a=`date +"%b-%d"`
  #4 (permalink)  
Old 12-08-2007
prowla prowla is offline
Read Only
  
 

Join Date: Nov 2007
Posts: 165
Just execute the date command you are using and compare its output to what you are trying to match (does it have a "-" in it?).
Also, check which options you are trying to print in your date (use the command "man date").
  #5 (permalink)  
Old 12-08-2007
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
the date is like "nov 23"

how to grep this
  #6 (permalink)  
Old 12-08-2007
anhtt anhtt is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 22
try to use this code

#!/bin/ksh
a=`date +"%b %d"`
ps -ef | grep root | grep "$a"
  #7 (permalink)  
Old 12-08-2007
prowla prowla is offline
Read Only
  
 

Join Date: Nov 2007
Posts: 165
Your command

a=`date +"%m-%d"`

has a "-" between the month and the date, but you are trying to match it to something that has a space there.

So

a=`date +"%m %d"`

should work.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0