run script to collect information every day but different directory

Nitiphone

New Member
Dear Any One,
Please kindly help me to find out some way to collect information as below?

zgrep "MCPKG" /centralizedlog/dsd0110{1,4}/afcdr/20190527/*.gz |grep success > save20190527.txt

I would like to run this command to collect information and put it to output file as this example
I can use crontab to run it but the problem is directory and file name always change every day

Thank you very much for your help.
 


Jetchko Jekov

New Member
How about using the 'date' command?
for example date +%Y%m%d, so something along the lines of:
zgrep "MCPKG" /centralizedlog/dsd0110{1,4}/afcdr/$(date +%Y%m%d)/*.gz |grep success > save$(date +%Y%m%d).txt
That's assuming you are looking at today's date. If you want this for day(s) in the past, then you need to do some calculations.
One way is $(date +%Y%m%d [email protected]$(($(date +%s)-86400*n))). Replace 'n' with the number of the days you want to go back.
Note that this it will work (most probably) only in 'bash'. For other shells, you have to figure out how to do subtraction and multiply by yourself.
 

Nitiphone

New Member
How about using the 'date' command?
for example date +%Y%m%d, so something along the lines of:
zgrep "MCPKG" /centralizedlog/dsd0110{1,4}/afcdr/$(date +%Y%m%d)/*.gz |grep success > save$(date +%Y%m%d).txt
That's assuming you are looking at today's date. If you want this for day(s) in the past, then you need to do some calculations.
One way is $(date +%Y%m%d [email protected]$(($(date +%s)-86400*n))). Replace 'n' with the number of the days you want to go back.
Note that this it will work (most probably) only in 'bash'. For other shells, you have to figure out how to do subtraction and multiply by yourself.
Hi,How about I need to use * on the same place with date

Like this
*20190818*

I would like to run this command below include star character(*)
awk -F',' '{if((substr($3,1,1)==1)&&($26~/Gateway_G/)&&($27~/SAP365/)) {print $2"|"$3"|"$23}}' /home/mone/billproxy/billdata/bpsbill/12/backup/*$(date +%Y%m%d [email protected]$(($(date +%s)-86400*1)))* | wc -l
but got error


Illegal variable name.
 

JasKinasis

Well-Known Member
To display the asterisks/stars as characters, you need to escape them using backslashes:
Bash:
awk -F',' '{if((substr($3,1,1)==1)&&($26~/Gateway_G/)&&($27~/SAP365/)) {print $2"|"$3"|"$23}}' /home/mone/billproxy/billdata/bpsbill/12/backup/\*$(date +%Y%m%d [email protected]$(($(date +%s)-86400*1)))\* | wc -l
 
  • Like
Reactions: Rob

Nitiphone

New Member
To display the asterisks/stars as characters, you need to escape them using backslashes:
Bash:
awk -F',' '{if((substr($3,1,1)==1)&&($26~/Gateway_G/)&&($27~/SAP365/)) {print $2"|"$3"|"$23}}' /home/mone/billproxy/billdata/bpsbill/12/backup/\*$(date +%Y%m%d [email protected]$(($(date +%s)-86400*1)))\* | wc -l
>awk -F',' '{if((substr($3,1,1)==1)&&($26~/Gateway_G/)&&($27~/SAP365/)) {print $2"|"$3"|"$23}}' /home/mone/billproxy/billdata/bpsbill/12/backup/\*$(date +%Y%m%d [email protected]$(($(date +%s)-86400*1)))\* | wc -l
Illegal variable name.

I tried but still got this error
 

JasKinasis

Well-Known Member
Hang on a second - are the asterisks part of a globbing pattern for a filename? If so - you definitely DON'T want to escape them.
Looking again - the problem isn't related to the asterisks.

I think the error message is something to do with your awk script.

I notice that the parts where you are looking at $26 and $27 don't have any comparison operators in there. Also the patterns you're looking for should probably be quoted.
So shouldn't this bit:
Code:
($26~/Gateway+G/)&&($27~/SAP365/)
Be something more like this?:
Code:
($26 == "~/Gateway+G/")&&($27 == "~/SAP365/")
So your whole command will be:
Bash:
awk -F',' '{if((substr($3,1,1)=="1")&&($26 == "~/Gateway_G/")&&($27 == "~/SAP365/")) {print $2"|"$3"|"$23}}' /home/mone/billproxy/billdata/bpsbill/12/backup/*$(date +%Y%m%d [email protected]$(($(date +%s)-86400*1)))* | wc -l
Does that fix the problem?
I've tried some simple tests using some .csv files I made myself - obviously I changed the file-path and used different fields in the files that I tested with - but that seems to work properly for me. Without any error messages.
 
Last edited:

Members online

No members online now.

Latest posts

Top