I have the following script (parts from help on this forum, thanks y'all):
The part that isn't working is the 2nd NAWK statement, particularly, where I have indicated "*$YEAR$MONTH$DAY".
I have the date set this way because I have several servers that will be receiving these queries, and the file names in each server starts with the server name, so I want to wildcard out the file name except for the same date on each server.
When I comment out this nawk statement, and just do an
I get every file in the directory, not just files from yesterday.
Last edited by Franklin52; 12-29-2011 at 10:39 AM..
Reason: Please use code tags for data and code samples, thank you
1. Please indent your code. Use code tags where necessary.
2. Looks like your initial steps to find the previous days' date is not working.
3. If you have bash try this: date -d"1 day ago" '+%m %d %Y'. Not sure if this'll work on ksh.
4. Or another work around to find yesterday's date is:
5. Again, this part in your awk is not fool-proof: d="$(date +%Y%m%d | awk '{printf"%8d\n",($1-1)}'. If date were to fetch "20111201", variable 'd' would hold "20111200" which isn't a valid date now, is it?
6. The reason you're getting all files is because, $YEAR$MONTH$DAY may not be holding any values. So, shell sees it as ** and not *$YEAR$MONTH$DAY*
Last edited by balajesuri; 12-28-2011 at 08:42 PM..
The first part of the script works good. It does indeed calculate the date for yesterday, and pulls the items I need.
I only have the problem on the second nawk command. Even when i just try to do
it gives me every file in the directory, not just the oens with yesterday's date.
Since the $YEAR$MONTH$DAY works in the first nawk cmmand i use (I confirmed with manual compilation) I cannot figure out why on the second one it is processing all of the files in the directory, not just the ones with yesterday's date.
What is a "code tag"?
Moderator's Comments:
How to use code tags when posting data and code samples.
You refer to the second "nawk" command. It it my eyes or does the first command say "nawk" and the second command say "awk" ???
I'll re-phrase that. Both the lines which start "nawk" have an "awk" further up the pipeline.
There is a left curly bracket { near the top of the script , but no matching right curly bracket }. Should it be between the last "esac" and the "for" ?
The purpose of the "awk" eludes me. It looks like the code from your previous thread which incorrectly attempts to calculate yesterday's date.
I have 2 lines that each start with "nawk". Agreed, each of those lines also have "awk" piped in the line, but I am referring to the the 2nd line that starts out with "nawk".
current date command runs well
awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat
subtract 30 days fails
awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat
awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
HI,
Can anyone tell me how to pull the date and file name separated by a space using the find command or any other command. I want to look through several directories and based on a date timeframe (find -mtime -7), output the file name (without the path) and the date(in format mmddyyyy) to a... (2 Replies)
greetings,
below is the find command i am using for some filesystem maintenance:
find /data/Engine \( -type d -name .snapshot -prune -o -type d -wholename "/data/Engine/*/CAE" \
-prune -o -type d -wholename "/data/Engine/*/CAD" -prune -o -name ".*.case" \)\
-mtime +365 -print0 -fls... (5 Replies)
Hi all,
Need an urgent help on the below scenario.
script:
awk -F","
'BEGIN { #some variable assignment}
{ #some calculation and put values in array}
END {
year=#getting it from array and assume this will be 2014
month=#getting it from array and this will be 05
date=#... (7 Replies)
Hi
I want to get tomorrow and yesterday date from date command. My shell is KSH and server is AIX. I tried several options, but unable to do. Please help on this.
Regards
Rajesh (5 Replies)
Hello everyone. My first time posting here.
I have a question that may seem very insignificant to some but is one that I've been trying to address for the past several days (haven't had any luck looking online).
I'm trying to clean a directory by removing old files that we no longer need.... (2 Replies)
I want to get previous date from date command. I am using ksh shell.
Exmp:
today is 2008.09.04
I want the result : 2008.09.03
Please help.
Thanks in advance. (4 Replies)
Hi there,
is it possible to use wild cards in this statement
ssh $remote_server 'perl -pi -e "s,EXP_SERIAL_19b8be67=\"\",EXP_SERIAL_`hostid`=\"UNKNOWN\"," /var/myfile'
This command works fine but the bit in bold (the 8 character hostid) will not always be 19b8be67 so I was hoping I could... (2 Replies)
when writing a shell script (bourne) and using a unix command like 'ls' is there anything special you need to do to use a wildcard (like *)? (3 Replies)