56 Comments
- as2003, on 10/12/2007, -1/+7Last time I checked, this was digg, not commentt.
- samuelcotterall, on 10/12/2007, -0/+4With Digg being about technology, and CRON being a somewhat important task to server administrators, I would say that quite a few people probably care...
Kinda interesting read. - radu79, on 10/12/2007, -0/+3Or just set it to run on the first day of the month, at 0:01 :D
- blah12345, on 10/12/2007, -0/+2For all the smarty-pants people saying "just use date --date", that must only work in Linux. It doesn't work in AIX. Can't say about the rest of the UNIX flavors.
- Mike.ohara, on 10/12/2007, -0/+2grimdotdotdot: you're fired.
- sclozza, on 10/12/2007, -0/+2Perl: It's self-obfuscating! :)
- amoeba, on 10/12/2007, -0/+2no worries, the great thing about computers is there's always something new to learn.
- vertigoblue, on 10/12/2007, -0/+2ill just do that and skip reading the article...
no, i'm really that lazy - arizonagroove, on 10/12/2007, -0/+2"Is this the Last Day of the Month?"
No, no it's not. - PaulOwen, on 10/12/2007, -0/+1That's basically it, punkcoder - the key is understanding that the .NET CLR has a method to get the number of days in a month. Once you have that, the rest is easy.
- dupy, on 10/12/2007, -3/+4Yep, I love .NET for good reasons. Go ahead and knock it, as everyone does. Ok, sure MS is abandoning it, ya right. Oh, what's that? It only runs on MS? Oh, ok...
At least I have a frickin' DateTime structure to work with...
YES, I know my comment has NOTHING to do with this post, and I'm a jerk for even adding my two-cents here. When I read this article though, I found myself glad that I do not have to deal with something like that as a programmer. Yep - I'm a MS developer, and happy about it for once! And YES, this does have to do with scripting jobs, because through WSH it is possible to use components, and I, as a .NET developer would use .NET for something as simple as that - yes I would. ;) Just for the hell of it... - amoeba, on 10/12/2007, -0/+1yeh, I must admit, I haven't looked into it in much detail.
I tend to use the CPanel interface in simple mode when creating a cron job.
It's easy to set up a job to run every hour but not so easy to set up a job to run every 65 minutes.
I'm not so familiar with the unix style interface.
//will look into it
//be nice - xaxa, on 10/12/2007, -0/+1Much simpler IMO:
Check against output of
date -d tomorrow +%d
I.e.
if [[ 01 = `date -d tomorrow +%d` ]];
then
echo first of month;
else
echo not first of month;
fi
(Change tomorrow to e.g. '1 may' to test.) - amoeba, on 10/12/2007, -0/+1This may help, if you use PHP
//get yesterday's date
$ago = 1; // days
$timestamp = time() - ($ago * 86400);
print date('Y-m-d', $timestamp);
another helpful function to get the time for a timezone different from the webserver's, prior to PHP5 (PHP5 has other functions you can use)
//calculate current date and time for specific timezone
$TimeDiff = -13; //this ones for Japan
$TimeZoneEpoc = time() - ($TimeDiff*60*60);
$currentDate = date('n/j/y',$TimeZoneEpoc);
$currentTime = date('g:i A',$TimeZoneEpoc);
print $currentDate." ".$currentTime;
HIH - eklitzke, on 10/12/2007, -1/+2@sedd
that actually made me laugh out loud :-) - BenRussoUSA, on 10/12/2007, -0/+1if [ `date --date=tomorrow +%d` -eq 01 ]; then echo INSERT SCRIPT HERE; else echo NOT TODAY; fi
- mahonemb, on 10/12/2007, -0/+1I've been having trouble coming up with Yesterdays date.
- as2003, on 10/12/2007, -1/+2Damn. You win!
- lydon, on 10/12/2007, -1/+2@jediboytj
I believe 32 people + Kevin Rose = 33 People.... just for future reference - buddyfarr, on 10/12/2007, -0/+1sorry, if the job has to be FINISHED by midnight then 1 second AFTER midnight would be, uh, too late.
- sedd, on 10/12/2007, -3/+4"Go ahead and knock it, as everyone does. Ok, sure MS is abandoning it, ya right. Oh, what's that? It only runs on MS? Oh, ok..."
You seem to have lost that argument you were having with yourself. - PaulOwen, on 10/12/2007, -0/+1In C#, making use of the handy DateTime.DaysInMonth method, this should do it correctly I think:
System.DateTime moment = new System.DateTime(System.DateTime.Now.Ticks);
int day = moment.Day;
Console.Out = (day == DateTime.DaysInMonth(moment.Year, moment.Month)) ? "Last day in the month" : "Not last day in the month"; - amoeba, on 10/12/2007, -0/+1I've looked into this more and it's not easy! Cron seems to be based on the current time and date not arbitrary time steps. You can run cron every 59 minutes and every hour but it looks impossible to run cron every 65 minutes. Have a look, you'll see what I mean...
- sembetu, on 10/12/2007, -0/+1hmm, check for tomorrow == 1st day of month at 0:01 today, if tomorrow == 1st, then run job, else if tomorrow != 1st read digg.
- inactive, on 10/12/2007, -0/+0sure every 65 min. "man cron"
- Xiol, on 10/12/2007, -0/+0man cron
- hussainweb, on 10/12/2007, -0/+0And I was thinking here how can 12th April be the last day of the month.
I was misled by the title. Happened to anyone else? - pixelbeat_, on 10/12/2007, -0/+0Yes that would be much simpler.
if [ `date --date="+1 day" +%d` = 01 ]; then
echo "last day of month"
fi - punkcoder, on 10/12/2007, -0/+0I'd guess in .Net you could get the current day of the month
int dayOfMonth = System.DateTime.Now.Day
Then compare that to the days in the month
int daysInMonth = System.DateTime.DaysInMonth(System.DateTime.Now.Year, System.DateTime.Now.Month)
Could probably shorthand that down some, but I'm guessing that's a way to do it. Sure there's some shorter ways in scripting, like checking if the day in the date tomorrow is 1, but I'm not a scripting expert. - quentinp, on 10/12/2007, -0/+0I usually just take the year and month and build a new date for the first of that year and month, then subtract one day, and then you are on the last day. Would I know how to do it in a cron job? I don't know to much Linux, but I think you spell corn c-o-r-n, so um that must be your problem. Don't know why you need corn though, maybe it's a farmer's computer?
- durzagott, on 10/12/2007, -0/+0Does anyone else find that the huge ad-thing in the middle of the page makes this article more of a pain to read than it's worth? What terrible formatting.
- sanjay, on 10/12/2007, -0/+0TItle is so useless...
doesnt say much about the story does it?
interesting read nevertheless
though i still prefer the 1st of the month @ 0:01 as already mentioned by radu79.....
but thats just me, is it? - xterminus, on 10/12/2007, -0/+0Just install another cron package such as fcron http://fcron.free.fr/ It allows date selection like this without requiring external scripts or other hackery. It also allows you to start (or queue) jobs based on criteria like cpu load so that your box doesn't get bogged down at midnight (or whatever) trying to run several jobs at once.
Still a neat example of some simple scriptage. - v3xt0r, on 10/12/2007, -1/+1you COULD do it in .NET, just as easily as you COULD get a hooker when you need to get laid.
I'd rather not stoop to that level though. =p - Jotham, on 10/12/2007, -0/+0I guess an article that just said, "Check if tomorrow is the 1st" would be too simple....
- jeolmeun, on 10/12/2007, -0/+0Some jobs may have to be finished by then.
- dupy, on 10/12/2007, -3/+3Well... since I'm such a "smartass," I WILL show you...
To start, I don't have to, as the author of this article suggested, use a command to spit the date out into my shell... THEN READ IT BACK (lol), to get the date... it's a bit simpler... smartass...
In VB no less...
Private Function IsItTheEndOfTheMonth() As Boolean
Dim objNow As System.DateTime = System.DateTime.Now()
Dim objTmw As System.DateTime = objNow.AddDays(1)
If objTmw.Day = 1 Then Return True
Return False
End If
Now, believe it or not... smartass... we can do this in C#, J#, and yes even PERL.NET (that's right - us .NET guys have even gone so far as to bastardize ur beloved PERL) MuWAHaHaHa! Pretty soon we'll probably have CRON.NET - although, to be honest - task scheduler suits the task just nicely anyway.
... smartass... - Grimdotdotdot, on 10/12/2007, -2/+2Comment Dupe!
http://digg.com/robots/RFID_Robot:_Someone_to_Watch_Over_Me
(Third one down)
;o) - tvolpe78, on 10/12/2007, -0/+0amen to that!
- BenRussoUSA, on 10/12/2007, -1/+0You can install GNU date utils on any UNIX system.
- leadingzero, on 10/12/2007, -3/+2@lydon
wrong, X people + Kevin Rose = Front Page - manchurian, on 10/12/2007, -1/+0Why not just do it on the first of the month at 00:00:01 ?
- tdyer, on 10/12/2007, -2/+1what?
you dont run man cron every 65 minutes you jackass.
stupid kids. - harlowsmonkeys, on 10/12/2007, -1/+0Set the clock ahead 86400 seconds. Then to run a cron job on the last day of the month, just put it in cron as running on the first day of the next month.
- amoeba, on 10/12/2007, -1/+0Cron is a great utility, I'd like to know how to set up a cron job to run every 1 hour and 5 minutes. Is that as simple as it sounds?
- kruykaze, on 10/12/2007, -1/+0Absolutely useless.
- Xiol, on 10/12/2007, -2/+0Ok smartass, just how would you do it with .NET?
Cron has been used and pretty much perfected for years. It's the perfect evolution of the right tool for the job. - jediboytj, on 10/12/2007, -4/+132 people + kevin rose?
-
Show 51 - 52 of 52 discussions



What is Digg?
Browsing Digg on your phone just got easier with our enhancements to the