<?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: Date option in scripting in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066786#M437962</link>
    <description>You can do it with caljd.sh and get your abbreviated month names AND the same command that can get yesterday can also skip past weekends so that Mon returns last Friday but Tuesday returns Monday. It's actually very simple.&lt;BR /&gt;&lt;BR /&gt;caljd.sh -o $(caljd.sh -x 6 -x 0 -p 1) | read MO DAY YEAR&lt;BR /&gt;echo "${MO} ${DAY}"&lt;BR /&gt;&lt;BR /&gt;The -x 6 says skip past Saturdays; -x 0 skips past Sunday, -p 1 says 1 previous day.&lt;BR /&gt;-o says print abbreviated month names rather than numeric months.&lt;BR /&gt;&lt;BR /&gt;We read the year but ignore it in the echo. All of this was in the usage of caljd.sh. Invoke as caljd.sh -u for full usage and many examples.&lt;BR /&gt;</description>
    <pubDate>Mon, 03 Sep 2007 11:43:22 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2007-09-03T11:43:22Z</dc:date>
    <item>
      <title>Date option in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066782#M437958</link>
      <description>I want to get yesterdays date in below format&lt;BR /&gt;&lt;BR /&gt;Sep  2 &lt;BR /&gt;&lt;BR /&gt;This is so that I can write a script to grep the date with below command&lt;BR /&gt;&lt;BR /&gt;yesterday=`TZ=GMT+23 date | cut -d " " -f 2,3,4`&lt;BR /&gt;cat /var/adm/syslog/syslog.log | grep "$yesterday" | grep -i -E 'crit|warn|ftp'&lt;BR /&gt;&lt;BR /&gt;The problem is that on Monday I need to get the list from Fridays date ( syslog is just an example and I will be using the script to get other date related logs as well)&lt;BR /&gt;How can I achieve this?&lt;BR /&gt;&lt;BR /&gt;I tried caljd.sh and can achieve this but the format is as below, Is there a way that I can change the format&lt;BR /&gt;&lt;BR /&gt;Caljd.sh date:&lt;BR /&gt;YESTERDAY=$(caljd.sh -y -s $(caljd.sh -p 3))&lt;BR /&gt;echo "Yesterday = ${YESTERDAY}"&lt;BR /&gt;&lt;BR /&gt; Yesterday = 20070831&lt;BR /&gt;&lt;BR /&gt;The sample script is below, might help you to understand what I want to achieve&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt; yesterday=`TZ=GMT+23 date | cut -d " " -f 2,3,4`&lt;BR /&gt;# Caljd command can also be used for friday&lt;BR /&gt;#friday=`TZ=GMT+?? date | cut -d " " -f 2,3,4`&lt;BR /&gt;HOSTNAME=`uname -n`&lt;BR /&gt;weekday=`date -u +%w`&lt;BR /&gt; &lt;BR /&gt;if ((weekday =1))&lt;BR /&gt;then&lt;BR /&gt;        echo "This is $HOSTNAME server"&lt;BR /&gt;# syslog&lt;BR /&gt;        echo "Syslog for $HOSTNAME"&lt;BR /&gt;        echo&lt;BR /&gt;        cat /var/adm/syslog/syslog.log | grep "$friday" | grep -i -E 'warn|crit'&lt;BR /&gt; &lt;BR /&gt;else&lt;BR /&gt;# syslog&lt;BR /&gt;        echo "Syslog for $HOSTNAME"&lt;BR /&gt;        echo&lt;BR /&gt;        cat /var/adm/syslog/syslog.log | grep "$yesterday" | grep -i -E 'ftp'&lt;BR /&gt; &lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Mon, 03 Sep 2007 09:21:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066782#M437958</guid>
      <dc:creator>Aggy</dc:creator>
      <dc:date>2007-09-03T09:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: Date option in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066783#M437959</link>
      <description>Shalom,&lt;BR /&gt;&lt;BR /&gt;Few places to look for date help.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://hpux.ws/merijn/caljd-2.25.sh" target="_blank"&gt;http://hpux.ws/merijn/caljd-2.25.sh&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://hpux.ws/merijn/caljd-2.2.pl" target="_blank"&gt;http://hpux.ws/merijn/caljd-2.2.pl&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;  LOGFILE="/tmp/memuse.mon.${FILTER}-`date +%d-%b-%Y`.log"&lt;BR /&gt;&lt;BR /&gt;The above two utilities, written by A. Clay Stephenson do a lot of troublesome date stuff for you.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Mon, 03 Sep 2007 09:29:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066783#M437959</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2007-09-03T09:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Date option in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066784#M437960</link>
      <description>Hi Aggy:&lt;BR /&gt;&lt;BR /&gt;use perl;&lt;BR /&gt;&lt;BR /&gt;# perl -MPOSIX -e 'print strftime "%b %1d\n",localtime(time-86400)'&lt;BR /&gt;&lt;BR /&gt;'strftime' returns fileds just like you return formatted fields from 'date'.  The computations occur in Epoch seconds; hence the current localtime less 86.400 seconds is exactly yesterday.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 03 Sep 2007 09:48:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066784#M437960</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-09-03T09:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Date option in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066785#M437961</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;What was it about the Perl script that didn't satisfy your original objective?:&lt;BR /&gt;&lt;BR /&gt;&amp;gt;  want to get yesterdays date in below format&lt;BR /&gt;&lt;BR /&gt;Sep 2 &lt;BR /&gt;&lt;BR /&gt;# yesterday=$(perl -MPOSIX -e 'print strftime "%b %1d\n",localtime(time-86400)')&lt;BR /&gt;&lt;BR /&gt;ALSO:&lt;BR /&gt;&lt;BR /&gt;You can drop the useless 'cat' and let 'grep' open and read the file:&lt;BR /&gt;&lt;BR /&gt;# grep "${yesterday}" /var/adm/syslog/syslog.log | grep -i -E 'crit|warn|ftp'&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 03 Sep 2007 10:28:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066785#M437961</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-09-03T10:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Date option in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066786#M437962</link>
      <description>You can do it with caljd.sh and get your abbreviated month names AND the same command that can get yesterday can also skip past weekends so that Mon returns last Friday but Tuesday returns Monday. It's actually very simple.&lt;BR /&gt;&lt;BR /&gt;caljd.sh -o $(caljd.sh -x 6 -x 0 -p 1) | read MO DAY YEAR&lt;BR /&gt;echo "${MO} ${DAY}"&lt;BR /&gt;&lt;BR /&gt;The -x 6 says skip past Saturdays; -x 0 skips past Sunday, -p 1 says 1 previous day.&lt;BR /&gt;-o says print abbreviated month names rather than numeric months.&lt;BR /&gt;&lt;BR /&gt;We read the year but ignore it in the echo. All of this was in the usage of caljd.sh. Invoke as caljd.sh -u for full usage and many examples.&lt;BR /&gt;</description>
      <pubDate>Mon, 03 Sep 2007 11:43:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066786#M437962</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-09-03T11:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Date option in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066787#M437963</link>
      <description>Hi (again) Aggy:&lt;BR /&gt;&lt;BR /&gt;My apologies for not reading!  You *did* say:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The problem is that on Monday I need to get the list from Fridays date &lt;BR /&gt;&lt;BR /&gt;Clay's script is an answer that works without re-invention AND has a plethora of useful options.   To redeem my failure to read, you could use this Perl script:&lt;BR /&gt;&lt;BR /&gt;# cat .prevworkday&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;use POSIX qw(strftime);&lt;BR /&gt;my $t = time();&lt;BR /&gt;my $d = strftime( "%u", localtime($t) );&lt;BR /&gt;my $n = $d == 1 ? 3 : $d == 7 ? 2 : 1;&lt;BR /&gt;print strftime "%b %1d\n", localtime( $t - ( $n * 86400 ) );&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...run as:&lt;BR /&gt;&lt;BR /&gt;./prevworkday&lt;BR /&gt;Aug 31&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 03 Sep 2007 12:50:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066787#M437963</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-09-03T12:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: Date option in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066788#M437964</link>
      <description>Thank You James and A.Clay&lt;BR /&gt;With your help I will be able to complete my script</description>
      <pubDate>Tue, 04 Sep 2007 09:30:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-option-in-scripting/m-p/5066788#M437964</guid>
      <dc:creator>Aggy</dc:creator>
      <dc:date>2007-09-04T09:30:04Z</dc:date>
    </item>
  </channel>
</rss>

