• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

Date Calculations in ksh script

I need to take x days away from todays date and then
compare this with dates from a file?

0
small
Asked:
small
  • 7
  • 4
  • 3
1 Solution
 
StapleheadCommented:
small,

take a look at the man pages for the find command.  the command:

        find . -mtime +10 -name '*.c'

will find all files which match *.c and have been modified greater than 10 days ago (whereas 10 would mean 'modified exactly 10 days ago', and -10 would mean 'modified less than 10 days ago).

of course, you could use a parameter to fill in the value of the number of days from the command line.

also, if you want to *do* something with the file(s) you find, you can use an -exec parm to the find command...


0
 
smallAuthor Commented:
Thank you for the quick response

Sorry, here is some more info..

I trying to work out 60 days from today and then comparing that
date with a list of dates from a file, not the date of a file.

i.e. a have a file which contains a list of user and their last
login date.  I want to identify all the users who have not logged
in in the last 60 days.

0
 
StapleheadCommented:
small,

if they haven't logged in, then their .history file wouldn't have been accessed.  assuming your users' accounts are under /users    :

   find /users -name '.history' -mtime +59

.will list all users' (history files) for users who haven't updated their history in 59 days or more...


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
smallAuthor Commented:
The list of usernames and dates come from a central security
server which covers 20+ machines.

I run a report on the security server and it outputs to a file
all the user information including last login, last password
change and a load of other info.

I want to take this file and produce a list of users who have
not logged in during the last 60 days.

I can only do this from the report file because I will
not be able to run a script which goes onto each of the
systems.

TIA.


0
 
ozoCommented:
What is the format of the dates in the file?
0
 
smallAuthor Commented:
ozo,

They are in the format of MM/DD/YY.

Once I get a script working, I will tackle the YY not YYYY problem.
0
 
ozoCommented:
perl -ne 'BEGIN{($d,$m,$y)=(localtime time-60*24*3600)[3,4,5]; $ymd=sprintf"%d%02d%02d",$y+1900,$m+1,$d} print if m"(\d+)/(\d+)/(\d+)" && "19$3$1$2" lt $ymd' < file
0
 
ozoCommented:
#!/usr/bin/ksh
#or in pure ksh, assuming your system accepts large TZ offsets:
ymd=`TZ=ZZZ1440;date +%Y%m%d`
IFS=$IFS/
exec < file
while read m d y x ;do
  if [[ "19$y$m$d" < "$ymd" ]] ;then
    echo $m/$d/$y $x
  fi
done
0
 
smallAuthor Commented:
ozo,

The ksh answer looks good.

Could you just give me a little more info on how the script works...

Thanks very much in advance.

Jonathan Small
0
 
smallAuthor Commented:
ozo,

I figured out the script.

How do I score your answer because yor replied in comments
rather than answers, I think.

This is my first question here so I'm not quite up to speed
with the procecure.

Bye Bye

0
 
StapleheadCommented:
small,

reject my answer, then let ozo propose...

Larry
0
 
smallAuthor Commented:
Ozo,

I have rejected the first answer.  Please answer so I can
grade your excellent response.

0
 
ozoCommented:
Ok, I'm glad it worked for you.
(it might have been more tricky if your system didn't like the time zone trick)
0
 
smallAuthor Commented:
Excellent!!!!

Thanks Ozo

Jonathan
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now