Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C Shell Date

Status
Not open for further replies.

SpongeBob1

Programmer
Mar 1, 2002
49
US
Hi,

I am trying to write a C Shell script that
1. Gets today's date
2. Finds a file ( eg. *.log) which is three days old.

Does anybody know how to do this?

Thanks.
 
I'm more familiar and prefer the k shell,
but this may work in the c shell.
As far as the date goes,
check out the man pages onn date.
You can alter the output to your liking.
here's an example
CUR_DATE=`/usr/bin/date "+%Y%m%d"`

You can use a find and/or grep combination
to find your file.

find /some/dir -mtime +2 -mtime -4
should find files that are three days old.

A better way may be to to calculate the date
three days ago and use a grep statement to find
that file.

Check out the faq faq80-953
At the bottom there is a script
to calculates yesterday's date
in a shell script. You should be
able to modify this to calculate
three days back.

Robert Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.
sh.gif


FREE Unix Scripts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top