I need to delete stats on every 2nd Sunday and I've try the following codes but unfortunately it didn't work. I'll really appreciate as always for your help. I'm on FreeBSD 8.2-STABLE.
If your cut/paste is accurate, your problem is likely because you have spaces round the equal sign in the assignment of day:
However, I question your logic. Deleting your file only when the execution day is the 8th through the 14th only cleans up once per month. If you want to delete every other week, wouldn't it be better to delete when the week number is either odd or even?
The above should delete on odd weeks and should do the right thing when there are 5 Sundays in a month.
I have tried your codes past two sundays and I was expecting on 06/03/2012 (it was odd sunday) the script should have deleted the stats but it seems it didn't work. Am i missing something?
Given that it's an "odd week" all week, what happens if you run this script?
You can run this manually to see what is happening.
You might also want to redirect your output and stderr from the script to a file rather than /dev/null. If there's an error in the script you'll be able to catch it. The way you have it coded you'll be scratching your head if there is a problem. I always like to have a log of what is kicked off by cron and usually put echo statements at key points (deleting files, skipping files in this case) so as to document that the script was run, and to know what it thought it did. Also to capture any error messages along the way.
---------- Post updated at 22:03 ---------- Previous update was at 22:00 ----------
I just noticed that you're running it with #!/bin/sh. If on your system that points to a "real" Borne shell (and not a more recent shell), then the syntax $(...) and ((..)) might not be valid.
Try replacing #!/bin/sh with the path for bash or kshell (in addition to adding some logging).
Yes, if you don't install bash/kshell it's probably not there by default.
Given that, the /bin/sh on FreeBSD (at least on the 8.2 system I tested on) is a more Borne like (probably POSIX) shell, and it's likely tripping over the if expression. When I tested your original code it evaluated the expression, but then tried to execute the result (1) rather than treating that as true. I just tried the code below and it seems to do just fine:
You might want to try changing your script to something like this. You could always code a dummy script (with echo statements rather than the rm statement), and set it off from cron before next Sunday rather than waiting all week.
Hi,
Actually scheduled my test scripts on test severs as shown below. They are supposed to run on 3rd sunday of every month.
Unfortunately it ran on 2nd sunday of the month (suspecting that it will run every sunday). I am sorry if I miss something. Could you please let me know if I did any... (1 Reply)
Hi All,
Can you please let me know how to get the yesterday's date of the given date if the given date is Sunday?
I can't use GNU. I have the code to get the yesterday's date based on the system date.
Thanks (5 Replies)
Hi,
Please can someone help me in getting first sunday date of a month.
i_year=`date +%Y`
ny_first_sun_nov=`cal 10 $i_year | sed '/^$/d' |head -3 |tail -1| rev | cut -c1`
This works good if the first sunday has a value but not if it is blank and first sunday falls on second week.
... (17 Replies)
Hi,
I want to get the second Sunday of march in any year, I have tried below command but it is not giving me the correct output
i_year=`date +%Y`
cal -m 03 $i_year | sed '/^$/d' |head -4 |tail -1|rev | cut -c1`
This is returning me 0 , where as I want 10.
Can you please help
Thanks (5 Replies)
Hi Am using unix Ksh
I have the two dates
DATE1=01/01/2013
DATE2=11/02/2013
In this two dates i need the output as count of sunday
sunday=6
Can anyone help me pls!!! (1 Reply)
Hi Am using Unix Ksh
I have a two date input as
DATE1=02/12/2012
DATE2=30/12/2012
I Need the output as only sunday date
02/12/2012
09/12/2012
16/12/2012
23/12/2012
30/12/2012
can anyone pls help me..
thanks in advance... (2 Replies)
Hi ,
I have a date parameter passed in YYYYMMDD format , how can I check whether it is Sat or Sun on Solaris box , as we can do the same easily on linux box by using date -d YYYYMMDD '+a' .
Any pointres will be really helpful . (5 Replies)
Dear all
How can I schedule the cronjob to be run sometime at every first Sunday at every month? I have the edit the cronjob every month now, thanks (2 Replies)
Hi All,
I have to kick off a script on every Monday to get some data from database for last week (Sunday thru Saturday).
If its Monday (12/12/2005)
Begin date will be Sunday - 12/4/2005
End date will be Saturday - 12/10/2005
The script might not kick off on some Mondays.
So my... (2 Replies)