<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Shell scripts for calculating the number of days betn DATES in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518709#M872191</link>
    <description>I like Thierry's approach for your problem but if you really want a nifty date calculator I've attached one that generate a small awk script and calculates a julian date (used by astronomers to essentially calculate an absolute number of days since ~4004 BCE).&lt;BR /&gt;You simply call the shell function&lt;BR /&gt;julian_day MM/DD/YYYY and it returns a number.&lt;BR /&gt;Call it with another date and subtract the two and ther you are.&lt;BR /&gt;</description>
    <pubDate>Thu, 19 Apr 2001 21:56:36 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2001-04-19T21:56:36Z</dc:date>
    <item>
      <title>Shell scripts for calculating the number of days betn DATES</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518704#M872186</link>
      <description>Hi Experts&lt;BR /&gt;          I am trying to write a script which calculates the difference between the two dates and gives it as the number of days say for Eg: between today 4/18/01 and 3/18/01 its 30 days.&lt;BR /&gt;               My aim is to monitor the last login time of a user and compare it with the system date and in case its more than 60 days I want to send a alert saying user has been idle. My client runs a NIS environment and he doesnt havee trusted systems.  I have tried writing the following script below, can you pl guide me and let me know if its the correct way?&lt;BR /&gt;&lt;BR /&gt;Thnks in advance&lt;BR /&gt;Shiv&lt;BR /&gt;_______________________________________________&lt;BR /&gt;&lt;BR /&gt;#! /bin/sh &lt;BR /&gt;OL=`TZ=PST+1440 date +%m%d` &lt;BR /&gt;TO=`date +%m%d` &lt;BR /&gt;LST=`last -1 karin | awk '{print $6}'` &lt;BR /&gt;MON=`last -1 karin | awk '{print $5}'` &lt;BR /&gt;case $MON in &lt;BR /&gt;       Jan) MO=01;; &lt;BR /&gt;       Feb) MO=02;; &lt;BR /&gt;       Mar) MO=03;; &lt;BR /&gt;       Apr) MO=04;; &lt;BR /&gt;       May) MO=05;; &lt;BR /&gt;       Jun) MO=06;; &lt;BR /&gt;       Jul) MO=07;; &lt;BR /&gt;esac &lt;BR /&gt;CK=$MO$LST &lt;BR /&gt;echo Last Login Date $CK &lt;BR /&gt;if [ $OL -lt $MO ] &lt;BR /&gt;       then &lt;BR /&gt;               echo This user has not loged last 60 days; &lt;BR /&gt;               echo This user has to be deleted ; &lt;BR /&gt;       else &lt;BR /&gt;               echo User logged within 60 days; &lt;BR /&gt;fi &lt;BR /&gt;</description>
      <pubDate>Thu, 19 Apr 2001 02:10:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518704#M872186</guid>
      <dc:creator>ShivKumar_1</dc:creator>
      <dc:date>2001-04-19T02:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: Shell scripts for calculating the number of days betn DATES</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518705#M872187</link>
      <description>Hi,&lt;BR /&gt;instead of really calculating the difference between the two dates, and relying on the fact that 'last' can supply the last login date,&lt;BR /&gt;I would go for another option:&lt;BR /&gt;- touch a file in their home dir each time they login  (touch $HOME/.lastlogin in their .profile)&lt;BR /&gt;- you can check if this file is recent with find:&lt;BR /&gt;--- find $HOME -name '.lastlogin' -mtime +60&lt;BR /&gt;&lt;BR /&gt;good luck,&lt;BR /&gt;Thierry.</description>
      <pubDate>Thu, 19 Apr 2001 06:13:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518705#M872187</guid>
      <dc:creator>Thierry Poels_1</dc:creator>
      <dc:date>2001-04-19T06:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: Shell scripts for calculating the number of days betn DATES</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518706#M872188</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;I think Thierry's approach is the most direct.  I would only add two comments:&lt;BR /&gt;&lt;BR /&gt;1.  'last' is an excellent choice.  It will only work if you have maintain (first touch) '/var/adm/wtmp'.  See the man pages for 'last'.  Depending on the number of users and logins you might not want to keep upwards of 60-days of information this way.&lt;BR /&gt;&lt;BR /&gt;2.  Assuming a posix or ksh shell is being used, you could track the HISTFILE file (normally $HOME/.sh_history) as your reference point.&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 19 Apr 2001 11:07:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518706#M872188</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-04-19T11:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: Shell scripts for calculating the number of days betn DATES</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518707#M872189</link>
      <description>I also found this thread that included a script for date calculating that you may want to check out also:&lt;BR /&gt;&lt;BR /&gt;Look for Al Langen post:&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0x57eff841489fd4118fef0090279cd0f9,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0x57eff841489fd4118fef0090279cd0f9,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;/rcw</description>
      <pubDate>Thu, 19 Apr 2001 11:23:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518707#M872189</guid>
      <dc:creator>Rita C Workman</dc:creator>
      <dc:date>2001-04-19T11:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Shell scripts for calculating the number of days betn DATES</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518708#M872190</link>
      <description>This is how I do such things.  I wrote a small C program that gets the number of seconds since an epoch.  Then I log this number somewhere.  Later, I run the program again and log this number.  Subtract the first number from the second and you get the number of seconds since you ran the command.  You can divide the difference by 60 to get minutes, and by 3600 to get hours since the commands were run.  This way you don't have to mess with leap years, crossing month and year boundaries, daylight savings changes, etc.. Here is the C code:&lt;BR /&gt;#include &lt;TIME.H&gt;&lt;BR /&gt;main(argc,argv)&lt;BR /&gt;   int argc;&lt;BR /&gt;   char ** argv;&lt;BR /&gt;{   &lt;BR /&gt;   time_t num_secs;&lt;BR /&gt;    num_secs=time(NULL);&lt;BR /&gt;   printf("%u",num_seecs);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;&lt;/TIME.H&gt;</description>
      <pubDate>Thu, 19 Apr 2001 21:16:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518708#M872190</guid>
      <dc:creator>Byron Myers</dc:creator>
      <dc:date>2001-04-19T21:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: Shell scripts for calculating the number of days betn DATES</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518709#M872191</link>
      <description>I like Thierry's approach for your problem but if you really want a nifty date calculator I've attached one that generate a small awk script and calculates a julian date (used by astronomers to essentially calculate an absolute number of days since ~4004 BCE).&lt;BR /&gt;You simply call the shell function&lt;BR /&gt;julian_day MM/DD/YYYY and it returns a number.&lt;BR /&gt;Call it with another date and subtract the two and ther you are.&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Apr 2001 21:56:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518709#M872191</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-04-19T21:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: Shell scripts for calculating the number of days betn DATES</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518710#M872192</link>
      <description>If you're running Byron's C program, and you're running in Trusted mode, there's a field in the user's tcb record that stores the users last successful login.&lt;BR /&gt;&lt;BR /&gt;Retrieve the field by doing something like&lt;BR /&gt;&lt;BR /&gt;mypr_passwdent=getprpwent();&lt;BR /&gt;&lt;BR /&gt;days_between=(time(NULL)-(&amp;amp;mypr_passwdent-&amp;gt;ufld.fd_slogin))/86400&lt;BR /&gt;&lt;BR /&gt;printf("%d days since last login",days_between);&lt;BR /&gt;&lt;BR /&gt;Note: this is code is meant as an example, man is your friend; this code is incomplete, but should give a C programmer enough to succesfully write a working utility.</description>
      <pubDate>Thu, 19 Apr 2001 22:06:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518710#M872192</guid>
      <dc:creator>Christopher Caldwell</dc:creator>
      <dc:date>2001-04-19T22:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Shell scripts for calculating the number of days betn DATES</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518711#M872193</link>
      <description>See the attachment.</description>
      <pubDate>Thu, 19 Apr 2001 22:20:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518711#M872193</guid>
      <dc:creator>Vincenzo Restuccia</dc:creator>
      <dc:date>2001-04-19T22:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Shell scripts for calculating the number of days betn DATES</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518712#M872194</link>
      <description>Hi Experts&lt;BR /&gt;                Thnks for the help,</description>
      <pubDate>Fri, 20 Apr 2001 17:33:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-scripts-for-calculating-the-number-of-days-betn-dates/m-p/2518712#M872194</guid>
      <dc:creator>ShivKumar_1</dc:creator>
      <dc:date>2001-04-20T17:33:53Z</dc:date>
    </item>
  </channel>
</rss>

