Operating System - HP-UX
1756546 Members
2844 Online
108848 Solutions
New Discussion

Re: Grep file contents by date

 
johan84
New Member

Grep file contents by date

Hi,

I need to calculate uptime for an application SAP, example is the contents of a file called VMCavailable.log 

07.07.2016 03:12:55 available: 0000s/3601s SGC: 0000s
07.07.2016 04:12:56 available: 0000s/3601s SGC: 0000s
07.07.2016 05:12:57 available: 0000s/3600s SGC: 0000s
07.07.2016 06:12:57 available: 0000s/3601s SGC: 0000s
07.07.2016 07:12:58 available: 0000s/3600s SGC: 0000s
07.07.2016 08:12:58 available: 0000s/3601s SGC: 0000s
07.07.2016 09:12:59 available: 0000s/3601s SGC: 0000s
07.07.2016 10:13:00 available: 0000s/3600s SGC: 0000s
07.07.2016 11:13:00 available: 0000s/2220s SGC: 0000s

When system is down it is indicated as such:

10.04.2016 21:09:35 system down 105s
04.05.2016 06:46:40 system down 1728000s
24.06.2016 20:00:34 system down 115s
24.06.2016 21:08:33 system down 89s

The previous guy's document had the following command penned:

more VMCavailable.log |grep month.year

This does not actually yield any results, sorry I know this is a stupid query. But I need this information rather urgently.

echo $TERM
vt100
echo $SHELL
/usr/bin/csh

version: Release: HP-UX B.11.31

Regards,

Johan

 

3 REPLIES 3
Steven Schweda
Honored Contributor

Re: Grep file contents by date

> more VMCavailable.log |grep month.year
>
> This does not actually yield any results, [...]

   Not a very useful problem description.  What, exactly, was the
command which you used?  What, exactly, happened when you used it?

   "more" on the front end (like that) makes little sense to me.  More
reasonable:

      grep month.year VMCavailable.log

or, if that gives you too much output, use "more" on the back end:

      grep month.year VMCavailable.log | more


> I need to calculate uptime [...]

   I'd need a better explanation of exactly what you want to calculate,
from what, to offer any suggestions on that.

 
> version: Release: HP-UX B.11.31

   Actual output from "uname -a" would be more informative/reliable.


> [...] stupid query.

   Elementary, perhaps.  It's not the same thing.  Missing useful info
is a bigger problem.  As usual, showing actual commands with their
actual output can be more helpful than vague descriptions or
interpretations.

Dennis Handly
Acclaimed Contributor

Re: grep file contents by date

>more VMCavailable.log | grep month.year

 

(I assume he meant you to replace month and year by the actual values.)

If you want all the lines for July 2016 you can use:

fgrep 07.2016 VMCavailable.log

Once you get that output, you need to use your business logic to compute your "uptime".

ranganath ramachandra
Esteemed Contributor

Re: Grep file contents by date

This command could get you the down time for the current month, you can modify it for the up times.

awk "/^.{2}$(date +%m.%Y).*down/{d+=int(\$NF)}END{print d}" < VMCavailable.log 

A good first step could be understanding exactly what the information in the log means and exactly what this command is trying to do.

 
--
ranga
[i work for hpe]

Accept or Kudo