Need help looking for missing hours.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help looking for missing hours.
# 1  
Old 06-05-2013
Question Need help looking for missing hours.

I have a file that should cover a days worth of stats, at the beginning of each 15 minute report I have a unique header that looks like the below example. The "0000" and "0015" will change in the header line to show which 15 Minute interval the report is covering and of course from day to day the "A20130604" will change based on the date. My thinking in the script is there should be 96 headers for a complete day.

Code:
A20130604.0000-0600-0015-0600_SubNetwork=DMME1,ManagedElement=ces-1

I am trying to write I quick "if else then" script to let me know if I have all the reports. I have tried the following:

Code:
#!/bin/ksh

x='cat /home/fsan/output/samfile | grep DMME | wc -l'
y=96

if [ "$x" -le 95 ]
then
        echo "You are missing files"
else
        echo "All hourly files appear to be present"
fi

When I run the file I get:
samcheck[4]: cat /home/fsan/output/samfile | grep DMME | wc -l: bad number

I have also tried changing the
Code:
if [ "$x" -le 95 ]

line to
Code:
if [ "$x" < $y ]

Then I get:
Code:
samcheck[5]: 96: cannot open

Any help on what I am doing wrong would be amazing!! I also wouldn't mind help on making a more dynamic script that can maybe tell me which hours I am missing.
# 2  
Old 06-05-2013
Here you store the string in x
Code:
x='cat /home/fsan/output/samfile | grep DMME | wc -l'
echo $x
cat /home/fsan/output/samfile | grep DMME | wc -l

You have mixed backtics `code` with 'code'

God way to do it.
Code:
x=$(cat /home/fsan/output/samfile | grep DMME | wc -l)

also works
Code:
x=`cat /home/fsan/output/samfile | grep DMME | wc -l`

other ways:
Code:
x=$(awk '/DMME/ {a++} END {print a}' /home/fsan/output/samfile)
x=$(awk '/DMME/' /home/fsan/output/samfile | wc -l)

This User Gave Thanks to Jotne For This Post:
# 3  
Old 06-05-2013
What about
Code:
[ $(grep -c DMME /home/fsan/output/samfile) -eq 96 ] && echo good || echo bad

?

I can't answer your question regarding which files are missing as I don't understand the time pattern in your file name. Pls explain.
This User Gave Thanks to RudiC For This Post:
# 4  
Old 06-05-2013
The time pattern is based on a 24 hour clock
Code:
A20130604.0000-0600-0015-0600_SubNetwork=DMME1,ManagedElement=ces-1

Code:
A20130604

is the date field A=the stream (we only have one stream but if we had multiple it would change) 20130604 = YYYYMMDD

Code:
0000-0600-0015-0600

0000 = The start time in the 15 minute report where 0000 is 12AM
0600 = Our system number so it will NEVER change
0015 = Then end time in the 15 minute report where 0015 is 12:15AM
0600 = Our system number so it will NEVER change

all the rest:
_SubNetwork=DMME1,ManagedElement=ces-1is just system info and will never change as well.
# 5  
Old 06-05-2013
So the 0000 should count up to 2345 (11:45 PM)?
# 6  
Old 06-05-2013
Let me start off by saying thank your to Jotne and RudiC for your quick and helpful answers, I greatly appreciate it

To RudiC's question:
Correct the first 0000 should count up to 2345 in increments of 15 minutes for example: 0000 , 0015, 0030, 0045, 0100, 0115

so the time lines will look like this:
Code:
0000-0600-0015-0600
0015-0600-0030-0600
0030-0600-0045-0600
0045-0600-0100-0600
0100-0600-0115-0600
0115-0600-0130-0600
0130-0600-0145-0600
0145-0600-0200-0600

and so on up to the final report of the day being
Code:
2345-0600-0000-0600


Last edited by Scrutinizer; 06-05-2013 at 03:49 PM.. Reason: code tags
# 7  
Old 06-05-2013
You might want to try
Code:
awk     '/DMME/ {ACT=substr($0,11,4)
                 if (ACT - EXP) print EXP
                 CNT += .25
                 EXP  = sprintf ("%04d", int(CNT)*100 + (CNT - int(CNT))*60)
                }
         END    {for (CNT; CNT<24; CNT+=.25) printf ("%04d\n", int(CNT)*100 + (CNT - int(CNT))*60)
                }
        ' file

---------- Post updated at 21:35 ---------- Previous update was at 20:48 ----------

Don't! It does not synchronize well once a line/time is lost. Try this:
Code:
awk     'BEGIN  {for (CNT=0; CNT<24; CNT+=.25) Arr[sprintf ("%04d", int(CNT)*100 + (CNT - int(CNT))*60)]}
         /DMME/ {delete Arr[substr($0,11,4)]}
         END    {for (i in Arr) print i}
        ' file

Pipe the result through sort | sort if you need the item in ascending sequence.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Fill in missing hours and interpolate values using awk.

I have a time series data like this 40754,35.6931,51.3092,201610160700,21.0 40754,35.6931,51.3092,201610160800,23.0 40754,35.6931,51.3092,201610160900,24.0 40754,35.6931,51.3092,201610161000,24.0 40754,35.6931,51.3092,201610161300,25.0 40754,35.6931,51.3092,201610161400,23.0... (6 Replies)
Discussion started by: emirzaei
6 Replies

2. Red Hat

Yum - resolving missing dependencies that are not missing

I am trying to install VirtualBox on RHEL 5 but I need the 32 bit version for 32 bit Windows. When I run yum I get the following: sudo yum localinstall /auto/spvtg-it/spvss-migration/Software/VirtualBox-4.3-4.3.2_90405_el6-1.i686.rpm Loaded plugins: fastestmirror Setting up Local Package... (13 Replies)
Discussion started by: gw1500se
13 Replies

3. SuSE

How to resolve missing missing dependencies with opensuse 11.3 and 12.3?

Hello, This is a programming question as well as a suse question, so let me know if you think I should post this in programming. I have an application that I compiled under opensuse 12.2 using g77-3.3/g++3.3. The program compiles and runs just fine. I gave the application to a colleague who... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

4. Shell Programming and Scripting

Get the no of hours between days

Hi, i have a date 1- 2013101511 date2 -2013101812 need toget the no of hours between them,can any one tellme the logic. (6 Replies)
Discussion started by: sandeep karna
6 Replies

5. Shell Programming and Scripting

ps -ef |grep 24 hours

I need to grep PIDs older than 24 hours (1 day) or more. ps -ef |grep ??? Please advise. (10 Replies)
Discussion started by: Daniel Gate
10 Replies

6. AIX

cron off by 5 hours

stupid question im sure, but its frustrating My cron jobs are off by 5 hours. My system time is right but all of my cron jobs are running approximately 5 hours late. Any idea why? (4 Replies)
Discussion started by: mshilling
4 Replies

7. Shell Programming and Scripting

CurrentTime-4 hours

Hi, Good Afternoon! I am writing this script on "sh" and have Variables as below. #Time in hours ex: 09 JobTime=`echo $StartTime |awk '{print $2}'|cut -f1 -d':'` SystemHours=`date +%H` How can go 4 hours back for each variable in a day? Another Question? JobStat=`dsjob -report... (5 Replies)
Discussion started by: rajubollas
5 Replies

8. What is on Your Mind?

How Many hours on Computer?

How many hours you spend on Computer in a day??? (10 Replies)
Discussion started by: malcomex999
10 Replies

9. Shell Programming and Scripting

how to list files between last 6 hours to 3 hours

Hi Frens, I want to list some files from a directory, which contains "DONE" in their name, i am receiving files every minute. In this i want to list all the files which are newer than 6 hours but older than 3 hours, of current time i dont want my list to contain the latest files which are ... (4 Replies)
Discussion started by: Prat007
4 Replies

10. Post Here to Contact Site Administrators and Moderators

Have we just had a rollback of a few hours?

Have we just had a rollback of a few hours? (1 Reply)
Discussion started by: porter
1 Replies
Login or Register to Ask a Question