Operating System - HP-UX
1753882 Members
7286 Online
108809 Solutions
New Discussion юеВ

Re: script to count files on daily basis

 
SOLVED
Go to solution
NDO
Super Advisor

Re: script to count files on daily basis

Patrick 

 

your second script worked fine, but I need to mail that output to an email address

Patrick Wallek
Honored Contributor
Solution

Re: script to count files on daily basis

Adding more requirements to the script?

 

Add this line to the end of the script:

 

echo "cdr: ${CDRCOUNT} \n tap: ${TAPCOUNT}" | mailx -s "cdr and tap file counts" you@somedomain.com
Steven Schweda
Honored Contributor

Re: script to count files on daily basis

> [...] but I need to mail that output to an email address

   What's stopping you?  Did you try a  Forum (or Web) search for, say:

      e-mail from shell script hp-ux

 

???

NDO
Super Advisor

Re: script to count files on daily basis

Thanks a lot, I knew that I needed to use mailx, but I was not sure how because of the requirement to display 2 outputs. But thank you

NDO
Super Advisor

Re: script to count files on daily basis

Hi

 

for some reason and since 31st of july, the script is providing erroneous output:

 

#!/usr/bin/sh

# Get yesterdays date
YESTMON=$(perl -MPOSIX -le '@t=localtime;--$t[3];print strftime "%Y %b %d",@t' | awk '{print $2}')
YESTDAY=$(perl -MPOSIX -le '@t=localtime;--$t[3];print strftime "%Y %b %d",@t' | awk '{print $3}')

CDRCOUNT=$(ls -lrt *.cdr | awk '{if (($6 == "'${YESTMON}'") && ($7 == "'${YESTDAY}'")) print $0}' | wc -l)
TAPCOUNT=$(ls -lrt *.tap | awk '{if (($6 == "'${YESTMON}'") && ($7 == "'${YESTDAY}'")) print $0}' | wc -l)

echo "cdr: ${CDRCOUNT}"
echo "tap: ${TAPCOUNT}"

and the output is:

cdr: 0
tap: 0

 

can you help

Dennis Handly
Acclaimed Contributor

Re: script to count files on daily basis

>for some reason and since 31st of july, the script is providing erroneous output:

 

What part isn't working?

Add: echo "Yesterday: $YESTMON|$YESTDAY"

 

As far as I can tell, this never worked during the first 9 days of a month.

You need to do a numeric compare:

CDRCOUNT=$(ls -l *.cdr | awk 'BEGIN {sum = 0} $6 == "'${YESTMON}'" && $7 ==
 '${YESTDAY}' {++sum} END {print sum}')
TAPCOUNT=$(ls -l *.tap | awk 'BEGIN {sum = 0} $6 == "'${YESTMON}'" && $7 ==
 '${YESTDAY}' {++sum} END {print sum}')

NDO
Super Advisor

Re: script to count files on daily basis

when adding echo "Yesterday: $YESTMON|$YESTDAY"

 

the result is:

 

Yesterday: Aug|03

and when changing with the piece of code you suggested, it does come right:

 

cdr: 1608
tap: 194

and if I place the script under a different directory and modify the script acordingly:

 

CDRCOUNT=$(ls -lrt /data/ICTPRD/bmd1/rating/processed/*.cdr | awk 'BEGIN {sum = 0} $6 == "'${YESTMON}'" && $7 == '${YESTDAY}' {++sum} END {print sum}')
TAPCOUNT=$(ls -lrt /data/ICTPRD/bmd1/rating/processed/*.tap | awk 'BEGIN {sum = 0} $6 == "'${YESTMON}'" && $7 == '${YESTDAY}' {++sum} END {print sum}')

produces the following results:

 

./contar[12]: /usr/bin/ls: The parameter list is too long.
cdr: 0
tap: 194

 

So...

Dennis Handly
Acclaimed Contributor

Re: script to count files on daily basis

>if I place the script under a different directory and modify the script accordingly:

 

"accordingly" means you have to handle mass quantities, which means you need to use find, not ll(1).

 

Or you can use this bandaid:

CDRCOUNT=$(cd /data/ICTPRD/bmd1/rating/processed;  ls -lrt *.cdr | awk 'BEGIN {sum = 0} $6 == "'${YESTMON}'" && $7 == '${YESTDAY}' {++sum} END {print sum}')

TAPCOUNT=$(cd /data/ICTPRD/bmd1/rating/processed; ls -lrt *.tap | awk 'BEGIN {sum = 0} $6 == "'${YESTMON}'" && $7 == '${YESTDAY}' {++sum} END {print sum}')

NDO
Super Advisor

Re: script to count files on daily basis

thanx a lot, already assigned kudos