<?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: Script to get data from wtmp in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044073#M433480</link>
    <description>I've tried a few more things; but sadly shell programming isn't my forte:&lt;BR /&gt;previous_month=$(expr`date +%m` -1)&lt;BR /&gt;sh: expr05:  not found.&lt;BR /&gt;/ # previous_month=`date +%m -1`&lt;BR /&gt;/ # echo $previous_month&lt;BR /&gt;05&lt;BR /&gt;&lt;BR /&gt;Sigh!&lt;BR /&gt;&lt;BR /&gt;It now occurs to me that I'll run into a problem when I try and get the data Jan for Dec data. I'll have previous month..but then I'll need previous year.&lt;BR /&gt;&lt;BR /&gt;Double Sigh!!&lt;BR /&gt;&lt;BR /&gt;Thanks again for any help&lt;BR /&gt;</description>
    <pubDate>Wed, 02 May 2007 21:17:41 GMT</pubDate>
    <dc:creator>Bob_165</dc:creator>
    <dc:date>2007-05-02T21:17:41Z</dc:date>
    <item>
      <title>Script to get data from wtmp</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044068#M433475</link>
      <description>OK script wizards---Here’s what I’m trying to do:&lt;BR /&gt;&lt;BR /&gt;On the first of every month (via cron) append a report called ‘secure’ with anyone who logged in etc via console or accessed a root command the previous month. I need to also make sure it’s the current year. &lt;BR /&gt;&lt;BR /&gt;I know how to get the year from wtmp you need to convert it:&lt;BR /&gt;/usr/sbin/acct/fwtmp /var/adm/tmp2&lt;BR /&gt;&lt;BR /&gt;cat /var/adm/tmp2 root console | egrep '$previous_month|$current year' | egrep ‘root|console’ &amp;gt;&amp;gt; /var/adm/secure&lt;BR /&gt;&lt;BR /&gt;How do I sent the variables for previous_month and current_year?&lt;BR /&gt;&lt;BR /&gt;This should be easy..&lt;BR /&gt;I tried current_year=’date “+Y%”’ but it doesn’t work and I don't have a clue on pervious_month.&lt;BR /&gt;…HELP!&lt;BR /&gt;&lt;BR /&gt;Thanks!!! &lt;BR /&gt;</description>
      <pubDate>Wed, 02 May 2007 17:09:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044068#M433475</guid>
      <dc:creator>Bob_165</dc:creator>
      <dc:date>2007-05-02T17:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Script to get data from wtmp</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044069#M433476</link>
      <description>#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset -i10 MO=1&lt;BR /&gt;typeset -i10 YR=0&lt;BR /&gt;&lt;BR /&gt;date '+%m %Y' | read MO YR&lt;BR /&gt;((MO -= 1))&lt;BR /&gt;if [[ ${MO} -lt 1 ]]&lt;BR /&gt;  then&lt;BR /&gt;    MO=1&lt;BR /&gt;    ((YR -= 1))&lt;BR /&gt;  fi&lt;BR /&gt;echo "Previous Month: ${MO} Year: ${YR}"&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 02 May 2007 19:45:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044069#M433476</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-05-02T19:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: Script to get data from wtmp</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044070#M433477</link>
      <description>Hi Bob:&lt;BR /&gt;&lt;BR /&gt;# current_year=`date +%Y`&lt;BR /&gt;&lt;BR /&gt;For the previous month name, constuct an array of names and index by the value of the current month less one.  Wrap-around if the current month is the last of a year.  &lt;BR /&gt;&lt;BR /&gt;# previous_month=`perl -le '@name=qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec c};$m=(localtime(time))[4];print $name[$m&amp;gt;0?$m-1:11]'`&lt;BR /&gt;&lt;BR /&gt;...I chose to use Perl since I can derive the current month (zero-relative) and perform the lookup in one easy swoop.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 02 May 2007 19:46:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044070#M433477</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-05-02T19:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Script to get data from wtmp</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044071#M433478</link>
      <description>Clay-&lt;BR /&gt;&lt;BR /&gt;Thanks but it comes back with:&lt;BR /&gt;Previous Month: 4 Year: 2007&lt;BR /&gt;Which yes 4 is previous to 5.&lt;BR /&gt;&lt;BR /&gt;What Iâ  m really looking for in the variable is the three char month i.e May, Aug since thatâ  s what I get out of wtmp converted to asci.&lt;BR /&gt;&lt;BR /&gt;So close!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;James--The date works perfect..&lt;BR /&gt;&lt;BR /&gt;Can you do the previous month in a shell (not perl) in the three char format.&lt;BR /&gt;&lt;BR /&gt;Thanks again..&lt;BR /&gt;</description>
      <pubDate>Wed, 02 May 2007 20:26:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044071#M433478</guid>
      <dc:creator>Bob_165</dc:creator>
      <dc:date>2007-05-02T20:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Script to get data from wtmp</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044072#M433479</link>
      <description>Hi (again) Bob:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Can you do the previous month in a shell (not perl) in the three char format.&lt;BR /&gt;&lt;BR /&gt;OK, but Perl is more fun :-)&lt;BR /&gt;&lt;BR /&gt;# cat ./lastmonth&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset -i M=`date +%m`&lt;BR /&gt;set -A name Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec&lt;BR /&gt;(( M -= 2 ))&lt;BR /&gt;if [ ${M} -lt 0 ]; then&lt;BR /&gt;   M=11&lt;BR /&gt;fi&lt;BR /&gt;echo ${name[M]}&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;...simply run:&lt;BR /&gt;&lt;BR /&gt;# ./lastmonth&lt;BR /&gt;Apr&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 02 May 2007 21:03:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044072#M433479</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-05-02T21:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Script to get data from wtmp</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044073#M433480</link>
      <description>I've tried a few more things; but sadly shell programming isn't my forte:&lt;BR /&gt;previous_month=$(expr`date +%m` -1)&lt;BR /&gt;sh: expr05:  not found.&lt;BR /&gt;/ # previous_month=`date +%m -1`&lt;BR /&gt;/ # echo $previous_month&lt;BR /&gt;05&lt;BR /&gt;&lt;BR /&gt;Sigh!&lt;BR /&gt;&lt;BR /&gt;It now occurs to me that I'll run into a problem when I try and get the data Jan for Dec data. I'll have previous month..but then I'll need previous year.&lt;BR /&gt;&lt;BR /&gt;Double Sigh!!&lt;BR /&gt;&lt;BR /&gt;Thanks again for any help&lt;BR /&gt;</description>
      <pubDate>Wed, 02 May 2007 21:17:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044073#M433480</guid>
      <dc:creator>Bob_165</dc:creator>
      <dc:date>2007-05-02T21:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: Script to get data from wtmp</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044074#M433481</link>
      <description>Hi Bob:&lt;BR /&gt;&lt;BR /&gt;Well, one way to compute the previous year is:&lt;BR /&gt;&lt;BR /&gt;# typeset -i Y=`date +%Y`;(( Y -= 1 ));echo $Y&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 02 May 2007 21:27:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044074#M433481</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-05-02T21:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: Script to get data from wtmp</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044075#M433482</link>
      <description>Hi Bob:&lt;BR /&gt;&lt;BR /&gt;...or if you like using 'expr' (which is slow and which causes the shell to invoke a new process):&lt;BR /&gt;&lt;BR /&gt;# Y=`expr $(date +%Y) - 1`&lt;BR /&gt;# echo ${Y}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 02 May 2007 21:33:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044075#M433482</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-05-02T21:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Script to get data from wtmp</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044076#M433483</link>
      <description>Thanks James &amp;amp; Clay..&lt;BR /&gt;&lt;BR /&gt;Perfect!!!!</description>
      <pubDate>Wed, 02 May 2007 21:36:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-data-from-wtmp/m-p/5044076#M433483</guid>
      <dc:creator>Bob_165</dc:creator>
      <dc:date>2007-05-02T21:36:49Z</dc:date>
    </item>
  </channel>
</rss>

