What will happen on the 1-st of a month?
What will happen on the 1-st of March of a leap/non-leap year?
vgersh99,
Nothing will happen with the code you supplied.
If you change it to:
It will find the files you want if you run it on days 11-31 in any month.
The first line calls nawk to convert the output of the date command (which today would be something like "Sun Jul 29 10:07:09 PDT 2012") to "Jul 28".
But, it will also list any other lines that contain "Jul 28" in the file name instead of in the date field. It won't work on the day 1-10 of any month because the awk command:
puts one space between the two values being printed, but the ls -l output has two spaces between the abbreviated month and the day for days 1 through 9 each month (which will keep the match of $0 to the awk variable d to fail).
Both of these problems can be fixed by keeping the abbreviated month name and the day of the month separate and matching them agains the 6th and 7th fields, respectively, in the output of ls instead of matching the combined fields agains the entire line.
But, it still won't work on the first of any month because the first command on the first of any month will set d to <MonthAbbreviation><space>0 and you'll never find ls -l output with a 0 as the day. So, using this method, you need to make your first awk command smart enough to convert the things like "Sun Jul 1 10:07:09 PDT 2012" to "Jun 30" instead of "Jul 0". If you have understood this much, I assume you now understand why leap years add to this complexity when calculating the previous day for March 1st.
The find -daystart primary suggested by RudiC with -mtime 1 would take care of this on some implementations, but I believe you said on another thread that you were running on OS/X and awk on OS/X doesn't provide the daystart primary.
On OS/X, the following should do what you want:
This User Gave Thanks to Don Cragun For This Post:
find list of files modified for a given day ?
if i have 10 files in my directory, i have modified only 5 ... how to display only modified files ? (1 Reply)
Hi All,
I have a requirement where I need to first capture the current day & move all the files from a particular directory based on a previous day.
i.e move all the files from one directory to another based on current day & a previous day. Here is what I am trying, but it gives me errors.... (2 Replies)
Hi All,
can anyone pls share the command to list the files of current day only. i want to check if there are any files in a particular directory which are not of current date. (6 Replies)
Hi,
I would like to write a script that checks if a file ('counter') was modified the previous day, if so erase its contents and write 00000000 into it.
For e.g. if the file 'counter' was last modified at 11.30pm on 24th May and the script runs at 12.15am of 25th May, it should erase it's... (1 Reply)
Hi,
i am developing a script for my project. In my script i need to check some conditions based upon some values. in that one value is the previous date. with the previous date i need to check and process some values. I have a function with me retrieve the yesterdays date.
But now i have a... (6 Replies)
Hi All,
I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this.
My Requirment is as below:
Input for me will be 2000909(YYYYMM)
I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
hi all.
Please help me with archiving previous day syslog files.
the files have no extension and have the format YYYY-MM-DD.
I want to archive the file then move it to some other machine.
thanks. (2 Replies)
Hi All,
I have a scenario where I need to download the previous day modified files from other server to my server through FTP . Could any one please send me the shell script for the same.
I used the following but I dont know how to proceed after this.
ftp -n -i -v $IP <<ENDOFinPUT >>... (3 Replies)
Hi,
I want a script(ksh) to see if today is the last working day(Mon-Fri) of the month. If it is the last working day I need to print current date, else I need the last working day of previous month. Thanks in advance. (1 Reply)
Hello,
Can you please help me how do i get previous and next working day of the week for a given date excluding saturday and sunday.
Ex: if the given date is monday, i should get friday and tuesday's date
if the given date is friday, i should get thrusday and monday's date.
Thanks,... (4 Replies)