[CALUG] Strange behaviour
Rajiv Gunja
opn.src.rocks at gmail.com
Mon Jun 24 15:27:23 EDT 2013
Yup! it was exactly due to the switch at the end of 23 hours 59 minutes.
I had to change my code to :
uptime | awk '{print $(NF-2)" " $(NF-1)" " $NF }'
that way I always have the last 3 columns, irrespective of the day.
After I saw that hour switch every 24 hours, I felt so ashamed of missing
that.
Thanks once again for the help.
-GG
-GG
On Wed, Jun 5, 2013 at 5:31 AM, John Szakmeister <john at szakmeister.net>wrote:
> On Tue, Jun 4, 2013 at 8:09 AM, Rajiv Gunja <opn.src.rocks at gmail.com>
> wrote:
> > This is not on Linux, but on Solaris/Unix.
> >
> > I have a few servers on which I am running a few commands via cron.
> > Examples commands: date, uptime, sar, netstat, dladm, prstat, ping.
> >
> > Here is the command sequence I am having the issue:
> >
> > ldavg=`uptime | cut -d":" -f4`
> >
> > DDATE1=`date +'%Y.%d.%h.%H.%M.%S'`
> >
> > echo "$DDATE1 >>> $ldavg" >> /var/adm/save/2ping/load.avg.log 2>&1
> >
> > In the log file, on some servers, once every hour, it will miss output of
> > the variable $ldavg. So the entried will look like this :
>
> That is strange. I initially thought maybe you were hitting a time
> where perhaps the time didn't have the extra colon for the seconds if
> you hit right on the minute boundary when executing uptime.
>
> > 2013.04.Jun.07.23.24 >>> 1.12, 1.23, 1.25
> >
> > 2013.04.Jun.07.24.29 >>> 1.03, 1.18, 1.23
> >
> > 2013.04.Jun.07.25.35 >>> 1.10, 1.18, 1.22
> >
> > 2013.04.Jun.07.26.40 >>> 1.45, 1.30, 1.26
> >
> > 2013.04.Jun.07.27.45 >>>
>
> I don't think this can be due to missing the output (I hope that
> couldn't happen!). Rather, since the line is there at all, I think
> it's more like the input string changed in a slightly unexpected way,
> so you're asking for a field that doesn't exist, which will come back
> empty.
>
> >
> > 2013.04.Jun.07.28.50 >>> 1.10, 1.23, 1.24
> >
> > 2013.04.Jun.07.29.55 >>> 1.08, 1.20, 1.23
> >
> > 2013.04.Jun.07.31.01 >>> 1.66, 1.29, 1.26
> >
> > 2013.04.Jun.07.32.06 >>> 1.27, 1.25, 1.25
> >
> >
> > I have no explanation as to why this would miss and that too at exactly
> that
> > time every hour. My script runs these commands once a minute, every hour.
>
> Perhaps a different tactic will work with the varying number of colons:
>
> uptime | sed -e "s/^.*: //"
>
> Just eat everything until the last colon and space, and what's left
> will be your averages.
>
> -John
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.unknownlamer.org/pipermail/calug/attachments/20130624/f8ba1942/attachment.htm
More information about the CALUG
mailing list