AWK - Issues with script running at start of month.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK - Issues with script running at start of month.
# 1  
Old 03-05-2012
AWK - Issues with script running at start of month.

I have a script that runs on an AIX 5.3.10.0. It runs perfectly on days that are double digit numbers, but from the 1st to the 9th of the month it runs but does not report anything.

The command in the script is as follows:

Code:
awk -v d=$(date '+%b%d') '/user:warn/ && /has shutdown/ && ($1$2 == d){ match($0,"The broker[^.][^.]*[.]");print $1,$2,$3 ":", substr($0, RSTART,RLENGTH)}' /var/mqsi/logs/CS/hub/user.log

I believe that there is an issue with the value that is being assigned to the $d variable, but can not figure out how to get around it. The way the variable is set at the moment with the %d displays the day of the month as a decimal number (01-31), using a 0 as leading space fill. In the file, there is no 0 padding, but an extra space is used (ie instead of 'Mar<space>06 08:27:49' the script will need to locate 'Mar<space><space>6 08:27:49').

I have tried substituting the %d with %e (Displays the day of the month as a decimal number (1-31). In a two-digit field, a blank space is used as leading space fill), and while this works when testing d=$(date '+%b%e') by itself, when I include it in AWK no results are produced.

As noted previously, I know this script works as if I run
Code:
awk '/user:warn/ && /has shutdown/ { match($0,"The broker[^.][^.]*[.]");print $1,$2,$3 ":", substr($0, RSTART,RLENGTH)}' /var/mqsi/logs/CS/hub/user.log

by itslef (not including the date parameters), a list of the required data is returned.

Can any one please advise what I need to do in order to make this script work all month round?

Last edited by jimbojames; 03-05-2012 at 08:01 PM..
# 2  
Old 03-05-2012
What you can do is to remove the leading zero before you feed into awk. Try this
Code:
set -- `date '+%b %d'`
mth=$1
day=${2#0}
awk -v d="$mth$day" '/user:warn/ && /has shutdown/ && ($1$2 == d){ match($0,"The broker[^.][^.]*[.]");print $1,$2,$3 ":", substr($0, RSTART,RLENGTH)}' /var/mqsi/logs/CS/hub/user.log

This User Gave Thanks to chihung For This Post:
# 3  
Old 03-05-2012
Thankk you chihung, that was what I was after!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Facing issues while running a cronjob !

Hi, I am trying to run a cronjob. But while doing so I am getting the following error message :- can't open yourfile in /var/spool/cron/crontabs directory. No such file or directory How can I resolve this issue ? Please help. Thanks Please view this code tag video for... (14 Replies)
Discussion started by: acidburn_007
14 Replies

2. Shell Programming and Scripting

Issues running an awk script

Hi, I have an awk script(test.awk) as below which I am trying to execute through the following command and I am getting error as follows. Request your valid inputs on where I am going wrong. Thanks. :/usr/chandra# awk -f test.awk input.txt syntax error The source line is 1. The error... (18 Replies)
Discussion started by: adept
18 Replies

3. UNIX for Dummies Questions & Answers

awk: issues for writing a script

%%%%% (7 Replies)
Discussion started by: lucasvs
7 Replies

4. UNIX for Dummies Questions & Answers

swap issues, system is running at 99%

Hi All, I am trying to understand why my system is running at very high. This system is almost out of memory. See below. swapon -s Filename Type Size Used Priority /dev/mapper/VolGroup00-LogVol02 partition 8388600 8235088 -1... (2 Replies)
Discussion started by: samnyc
2 Replies

5. UNIX for Dummies Questions & Answers

Running Script via Crontab on 2nd Working day each month

Hello Guys, I have a questions regarding running a shell script every second working day each month. I have no clue how solve this problem :wall:. Important is that it has to be the second working (Mo-Fr). Example: If 1st and 2nd Days of month are Sat and Sun the script must run on 4th day... (5 Replies)
Discussion started by: Hollo
5 Replies

6. Shell Programming and Scripting

Need help in running script on last day of month

Hello Experts/Guru, I need a help in running the script on every month last day.... PS: due to some constrain I can't schedule in crontab Requirement: On Jan 31st i want to run some script, similarly on Feb 28th, March 31st, April 30th......till Dec 31st. Please help me by providing... (3 Replies)
Discussion started by: aks_1902
3 Replies

7. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

8. UNIX for Advanced & Expert Users

Autosys Job Running every 5th Day of Month

Hi, Is there a way to schedule a job in Autosys to run every 5th Day of Month without using custom calendar? Thanks. (1 Reply)
Discussion started by: vbhatnag
1 Replies

9. UNIX for Dummies Questions & Answers

How to start application and keep script running

What I'm looking for is best explained with a little example. #!/bin/bash gedit echo "I need this message to appear while gedit is still running, but it appears only then when I close gedit." Of course most of the times you want the script to wait, but in this case I want to start a new... (5 Replies)
Discussion started by: MrZehl
5 Replies

10. UNIX for Advanced & Expert Users

Problem in running an AWK script

Hi Everyone, I am required to write an AWK script that can be run from any directory. This script finds subscription rates for each subscriber at an interval of 10 mins. I want that just by copy pasting the whole script in shell prompt and giving the input arguments, script must work. Currenty... (4 Replies)
Discussion started by: rachana8p
4 Replies
Login or Register to Ask a Question