[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Date Calculations in ksh script

Posted on 1998-07-08
14
Medium Priority
?
251 Views
Last Modified: 2013-12-26
I need to take x days away from todays date and then
compare this with dates from a file?

0
Comment
Question by:small
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
14 Comments
 
LVL 1

Expert Comment

by:Staplehead
ID: 1294578
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
 

Author Comment

by:small
ID: 1294579
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
 
LVL 1

Expert Comment

by:Staplehead
ID: 1294580
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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:small
ID: 1294581
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
 
LVL 84

Expert Comment

by:ozo
ID: 1294582
What is the format of the dates in the file?
0
 

Author Comment

by:small
ID: 1294583
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
 
LVL 84

Expert Comment

by:ozo
ID: 1294584
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
 
LVL 84

Expert Comment

by:ozo
ID: 1294585
#!/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
 

Author Comment

by:small
ID: 1294586
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
 

Author Comment

by:small
ID: 1294587
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
 
LVL 1

Expert Comment

by:Staplehead
ID: 1294588
small,

reject my answer, then let ozo propose...

Larry
0
 

Author Comment

by:small
ID: 1294589
Ozo,

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

0
 
LVL 84

Accepted Solution

by:
ozo earned 400 total points
ID: 1294590
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
 

Author Comment

by:small
ID: 1294591
Excellent!!!!

Thanks Ozo

Jonathan
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question