Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 07-09-2008, 08:36 AM   #1
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
Random Cron Job Possible? or alternative?

i want to execute a script once per day randomly in a 6 hour period e.g. execute a script between 5am and 11am every day. obviously if i'm using a cronjob it's got to be a regular time every day, anyone got a suggestion of how i can execute it randomly?

thanks in advance

Last edited by roly; 07-09-2008 at 08:37 AM..
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 08:40 AM   #2
xenilk
Confirmed User
 
xenilk's Avatar
 
Join Date: Jan 2006
Location: Canuck land!
Posts: 921
My idea of doing this would be to run the cronjob multiple time over the 6 hour span and have a random variable inside the script to make it execute or not. You will also need a value stored somewhere to see if you've already executed the script within the last 6 hours.

Good luck!
xenilk is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 08:55 AM   #3
Babaganoosh
♥♥♥ Likes Hugs ♥♥♥
 
Babaganoosh's Avatar
 
Industry Role:
Join Date: Nov 2001
Location: /home
Posts: 15,841
Quote:
Originally Posted by xenilk View Post
My idea of doing this would be to run the cronjob multiple time over the 6 hour span and have a random variable inside the script to make it execute or not. You will also need a value stored somewhere to see if you've already executed the script within the last 6 hours.

Good luck!
Exactly.

Generate a random number between 1-10, then if the random number is < or = a variable then execute the script. Otherwise exit with no action taken. If you set the variable to 2 for instance your script would have a 20% chance of executing.
__________________
I like pie.
Babaganoosh is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 09:11 AM   #4
Dido
Confirmed User
 
Dido's Avatar
 
Industry Role:
Join Date: Sep 2006
Location: Netherlands
Posts: 217
Actually, that still leaves the chance that your script will never, ever execute.
Try just cronning your script once and having your script sleep for a randomized number of seconds.
That way, it will run, you just won't be certain when

(By the way, shells by default don't have a random number generator as far as I know. You might have to find yourself a random number "program" for that)
__________________
Dido

ADAMO Advertising - Your ULTIMATE traffic partner!

If you need traffic or have traffic, we'd love to help you make the best out of it!

ICQ:24209500 - Skype:diederikvanschaik
Dido is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 09:13 AM   #5
Dido
Confirmed User
 
Dido's Avatar
 
Industry Role:
Join Date: Sep 2006
Location: Netherlands
Posts: 217
Oh, actually. It seems that bash has something of a $RANDOM enviroment variable which is .. probably pseudo-random enough for what you want.
__________________
Dido

ADAMO Advertising - Your ULTIMATE traffic partner!

If you need traffic or have traffic, we'd love to help you make the best out of it!

ICQ:24209500 - Skype:diederikvanschaik
Dido is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 09:19 AM   #6
Babaganoosh
♥♥♥ Likes Hugs ♥♥♥
 
Babaganoosh's Avatar
 
Industry Role:
Join Date: Nov 2001
Location: /home
Posts: 15,841
Quote:
Originally Posted by Dido AskJolene View Post
Actually, that still leaves the chance that your script will never, ever execute.
Try just cronning your script once and having your script sleep for a randomized number of seconds.
That way, it will run, you just won't be certain when

(By the way, shells by default don't have a random number generator as far as I know. You might have to find yourself a random number "program" for that)
That's kinda true. I didn't really read his post. There's still a simpler way to do this.

Generate a random number between 1-6. Store that along with the date in a flat file. When the script runs, have it choose a number between 1-6. If that = the random number then execute the script.

You'd have to keep track of the numbers already picked for the day as well as increment the date after the script has already run for the day. Make sure the script doesn't execute again if the date in the text file == today.
__________________
I like pie.
Babaganoosh is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 09:37 AM   #7
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
thanks guys for all the responses, there's some good sugestions there, i'll go away and have a play with it and see if i can come up with something using your suggestions. i'll post back if i come up with something usable. too be honest i assumed there would already be a utility or something that did this already.

thanks again
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 09:38 AM   #8
Babaganoosh
♥♥♥ Likes Hugs ♥♥♥
 
Babaganoosh's Avatar
 
Industry Role:
Join Date: Nov 2001
Location: /home
Posts: 15,841
Quote:
Originally Posted by roly View Post
thanks guys for all the responses, there's some good sugestions there, i'll go away and have a play with it and see if i can come up with something using your suggestions. i'll post back if i come up with something usable. too be honest i assumed there would already be a utility or something that did this already.

thanks again
There may be something out there already. I'm a programmer by trade so it's in my nature to over-complicate everything.
__________________
I like pie.
Babaganoosh is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 09:48 AM   #9
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
Quote:
Originally Posted by Babaganoosh View Post
There may be something out there already. I'm a programmer by trade so it's in my nature to over-complicate everything.
i'm not a programmer as you can probably tell

i'm just having a quick search on google and found the php sleep() function (its a php script i'm trying to run). which maybe a solution but has anyone used this before and if so can i use this for a period of hours (2 hours would do)? and would this function be affected by my php.ini settings e.g. max_exectution_time
etc?

Last edited by roly; 07-09-2008 at 09:51 AM..
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 10:41 AM   #10
d-null
. . .
 
d-null's Avatar
 
Industry Role:
Join Date: Apr 2007
Location: NY
Posts: 13,724
Quote:
Originally Posted by Babaganoosh View Post
That's kinda true. I didn't really read his post. There's still a simpler way to do this.

Generate a random number between 1-6. Store that along with the date in a flat file. When the script runs, have it choose a number between 1-6. If that = the random number then execute the script.

You'd have to keep track of the numbers already picked for the day as well as increment the date after the script has already run for the day. Make sure the script doesn't execute again if the date in the text file == today.

why 1-6?
__________________

__________________

Looking for a custom TUBE SCRIPT that supports massive traffic, load balancing, billing support, and h264 encoding? Hit up Konrad!
Looking for designs for your websites or custom tubesite design? Hit up Zuzana Designs
Check out the #1 WordPress SEO Plugin: CyberSEO Suite
d-null is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 10:46 AM   #11
ADL Colin
Too lazy to set a custom title
 
ADL Colin's Avatar
 
Join Date: Feb 2001
Location: Tube Titans, USA
Posts: 11,929
Quote:
Originally Posted by jetjet View Post
why 1-6?
6 hours. You could use 7 and include both end points.

5am 6am 7am 8am 9am 10am 11am
__________________


Adult Date Link - $50 PPS starting NOW! -- good and JUICY!

skype = "adultdatelink"
ADL Colin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 10:47 AM   #12
buyandsell
Confirmed User
 
Industry Role:
Join Date: May 2008
Location: USA
Posts: 692
just make a wrapper in perl or something
buyandsell is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 10:51 AM   #13
gornyhuy
Chafed.
 
gornyhuy's Avatar
 
Join Date: May 2002
Location: Face Down in Pussy
Posts: 18,041
A simpler approach:
1)Have 1 daily cron job run a script that generates a random time tag for the day and store it in a db or text file
2)have a second cron running once ever 30 minutes or whatever and check to see if it has passed the randomly generated time. If it has, fire off the task and reset the stored time so it only does it once.
__________________

icq:159548293
gornyhuy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 12:24 PM   #14
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
Quote:
Originally Posted by gornyhuy View Post
A simpler approach:
1)Have 1 daily cron job run a script that generates a random time tag for the day and store it in a db or text file
2)have a second cron running once ever 30 minutes or whatever and check to see if it has passed the randomly generated time. If it has, fire off the task and reset the stored time so it only does it once.
this looks like the way i'll make it work, thanks
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 12:38 PM   #15
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Why not just use cron to do a daily 'at'? I fail to see the need for abusing cron for two jobs that cron, and at, would do better.
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-09-2008, 01:48 PM   #16
teg0
Confirmed User
 
teg0's Avatar
 
Join Date: Jan 2006
Location: Gringo in Puerto Rico
Posts: 4,204
run the cron job at a set time, but have the code that it runs, php or other hand the randomization. A simple example would be to have it generate a random number between 1 and 10 and if the number if 7 then run execute the rest of the job, if not exit.... then it'll try it again next time the cron job runs. You'd be bound to have it be 7 now and then.
teg0 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-10-2008, 12:13 PM   #17
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
Quote:
Originally Posted by GrouchyAdmin View Post
Why not just use cron to do a daily 'at'? I fail to see the need for abusing cron for two jobs that cron, and at, would do better.

i've never heard of 'at' before with regards to cron, will that achieve some sort of randomization?
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.