Musings of a *IX guy

All things Unixy and not Unixy
  • rss
  • About
  • Tuqix front page
  • Blog

Finding the date x number of days ago in the shell

Dave | July 8, 2009

If you need to find what the date was X number of days ago in AIX ( 5.3 or greater ), or Linux  :-

First convert the number of days to hours e.g. if you want to find the date 90 days ago you need 90 * 24 = 2160

echo `TZ=GMT+2160 date +%d/%m/%y`

You can of course use any of the % formats to get the output you require.

To compare two dates ( very useful in AIX to see if a user has not logged in for 90 days for example ) use the %s to get the number of seconds since 1st Jan 1970 :-

echo `TZ=GMT+2160 date +%s`

lsuser  -a time_last_login username   ( needs to run as root )

Then compare the two numbers and if the 90 days ago number is gretaer than the output of the lsuer command then that user has not logged in for gretaer than 90 days

Comments
1 Comment »
Categories
AIX, Linux
Comments rss Comments rss
Trackback Trackback

Navigation

  • AIX
  • Applications to install on a personal web site
  • Centos
  • Email
  • Hi-Fi
  • Linux
  • Linux desktop
  • TSM
  • Uncategorized
  • VPS server
  • Websphere
  • Wordpress

Search

rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox