Trouble With Script When Using a timerange in AM that spans into PM


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trouble With Script When Using a timerange in AM that spans into PM
# 1  
Old 07-07-2010
Trouble With Script When Using a timerange in AM that spans into PM

Attachment 1551I have a script where a user provides a date, start time and end time. The script will take these values and scan a log file to search for key words in the log file that fall within the time range. When a user uses AM times (Example: 700 to 900 - this is 7am to 9am) as a range or PM times (Example: 1400 to 1600 - this is 2pm to 4pm) as a range the script works fine. when they use an AM start time and a PM end time the script does not function properly. I've attached the script.

Here is the line in question that I"m having problems with if people don't want to look at the entire attached script.
echo "Number of ${shipmentTags[$i]} shipments processed in log file log$logDate/$logFileName is:`cat $logDirectory/log$logDate/$logFileName | awk -F":" '$1$2 >= '"$startTime"' && $1$2 <= '"$endTime"' {print $0}' | grep ${shipmentStrings[$i]} | wc -l`"

Thanks. I've copied here just some dummy data of what the log would look like.

07:00:01.124 dfsdfjsdflkjsdfkljsdflkjEDIRequestServiceModule/Routedasdfkl
07:05:02.123 fsldjfsdfskdfjsdfsdkfjEDIRequestServiceModule/Rouedsdfjsdfj
07:10:33.233 sdkjfasdflkjasdfaskdfjasdfkljEDIRequestServiceModule/Routed
09:30:02.222 sefsklfjsdfljksdfEDIRequestServiceModule/Routedasdfdf
14:00:12.222 sdfsdfsdfsdfsdfsdfEDIRequestServiceModule/Routed sdfsdfs
14:01:22.223 sdfsdfsdfsdfsdfsdfsdfEDIRequestServiceModule/Routed sdfsdfsdf
17:00:22.222 sdfsdfsdfsdfsdfsdfEDIRequestServiceModule/Routedsdfsdfsdf
18:00:33.333 sdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdf

Last edited by biddieboy; 07-14-2010 at 12:05 PM..
# 2  
Old 07-07-2010
variables inside awk

One thing I noticed, and I will have to go back and look further, but you are referencing a shell variable within awk. But, you do not appear to pass the variable into awk.

for instance, something like...
awk -v myvar=$var1 '{ blah blah with myvar }'
# 3  
Old 07-07-2010
Awk variables

i'm not sure declaring the variables to awk would make a difference b/c i'm not currently doing that now and the script works fine as long as i don't put in a time range that starts in the AM (700) and ends in the PM (1400). Any more thoughts?

Thanks for the quick reply though.
# 4  
Old 07-12-2010
Can anyone please take a look...its been several days now and I've had no responses. Even just some steps in the right direction would be great. Thank you.
# 5  
Old 07-12-2010
What happens with a AM time that is greater than 09:59, and any PM time? (thinking it might be a leading 0 problem, maybe?)

Can I assume that the log files will have one entry per line, and do not have dates?
# 6  
Old 07-12-2010
When i have an AM time (from-time) that is greater than 9:59 and a to-time that is greater than 9:59, the script works fine and the counts show up correctly. The script also works if there is an AM time (from-time) that is less than 10:00 and the other time (to-time) is less than 10:00. Its weird...when the AM time (from-time) is less than 10:00 and the other time (to-time) is greater than 9:59, that's when the script doesn't work.

You are correct on your assumption.
# 7  
Old 07-12-2010
Hmm, any chance you could cheat, and run the log file through a sed statement and have it pull out ^0 and see what happens with no leading zeros in the log?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX Sort on a field that spans multiple columns

New to unix. I need to sort the records of a file by a control number field. That field is in POS 16 through 28. How do I do that? There are no delimiters, or spaces to separate fields. See example below. Each line is a record. REC1CCYYMMDD0018888888888888ABCDE... (1 Reply)
Discussion started by: jclanc8
1 Replies

2. Shell Programming and Scripting

Having trouble with My Bash Script, need Help debugging

Hello Friends I am having trouble with my script below. I will describe the problems below the code box. I am hoping that some of the experts here can help me. #!/bin/bash #========================================================================================================= # Rsync File... (8 Replies)
Discussion started by: jdavis_33
8 Replies

3. Shell Programming and Scripting

I am having trouble with this count script

I have to display the file name followed by the line count then work count. I am able to display it in the opposite order, but can figure out how to switch it. Can anyone help me with this it would be greatly appreciated. My code is as follows: #!/bin/bash # #Conts and displays the... (5 Replies)
Discussion started by: football12345
5 Replies

4. Shell Programming and Scripting

trouble looping in script

I am having problem looping this script I want to give the user option to decide if they want to continue after each entry but then also loop it back to beginning so they can more to content of there testcase they just created. I fam new to scripting so loops are little tricky for me. code I... (7 Replies)
Discussion started by: andrew.p.mcderm
7 Replies

5. UNIX for Dummies Questions & Answers

trouble with snmpwalk script

I am using a line of code that I borrowed from someone else's script, in a script to monitor changes in my local network. It works but it takes too long to pick up the changes. snmpwalk -v 2c -c PASSWORD -Oq 10.0.1.1 RFC1213-MIB::atPhysAddress The snmp server is my apple router. If I monitor... (7 Replies)
Discussion started by: chancho
7 Replies

6. Homework & Coursework Questions

unix script trouble

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi I am new to unix and need some help, the main reason I am here is because i need basic unix knowledge The... (2 Replies)
Discussion started by: krolike
2 Replies

7. Shell Programming and Scripting

Grep using REGEX that spans several lines

Hi all, I need help regarding the following: I need to support text search (number of text occurrences), in user specified - text file and - 'REGULAR EXPRESSION'. >grep -c 'pattern' fileToSearch was working successfully until I was requested to SUPPORT "\n"(new line separator in user... (1 Reply)
Discussion started by: epro
1 Replies

8. Shell Programming and Scripting

trouble making a useradd script

i'm new to scripting in unix and am trying to make a script to add a user and an encrypted password for them. this is what i have and it isn't giving me any errors, but when i try to login with the new user, the password doesn't work. i'm hoping someone can point me in the right direction ... (1 Reply)
Discussion started by: patt4179
1 Replies

9. Shell Programming and Scripting

trouble in running script

HI admin unix, I'm from indonesia that currently work as system admin for server under AIX/UNIX environment. I have some trouble when running script as follow : ## vdate() { sqlplus -s ${MMUSER}/${PASSWORD} <<-eot|grep -v '^$' set heading off feedback off select... (2 Replies)
Discussion started by: cahyo3074
2 Replies

10. Shell Programming and Scripting

trouble with script

I'm having a little trouble finishing up this script any help would be great. My system is SCO OpenServer Enterprise System (ver 5.0.5m) and i'm using sh This script checks todays date and goes and downloads a file with yesterdays date in the name. ---start---- Server="ipaddresshere"... (4 Replies)
Discussion started by: whegra
4 Replies
Login or Register to Ask a Question