Cron job randomly once a day


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cron job randomly once a day
# 1  
Old 10-30-2010
Error Cron job randomly once a day

I want to create a cron job randomly once a day for my site's registration.
The responsible file for registrations is a config file and I need to change the contents
twice on day (on and off)
I know the way for random cron job for example
Code:
*/n * * * * /usr/local/bin/php /home/user/domain.com/cron.php >/dev/null 2>&1(registrations on)

but i don't know how to change the values after one hour to normall (registrations off)..
Any suggestions on this>??
Sorry for my bad English
Thank you in advance

Last edited by Scott; 10-31-2010 at 02:10 PM.. Reason: Code tags
# 2  
Old 10-31-2010
maybe use the "at" command instead ?
# 3  
Old 10-31-2010
To get some help about how to use the at command enter this :
man at | less
# 4  
Old 10-31-2010
What OS do you have? -- simply using at will start a job, but you have to give it offset times, and those vary a little by OS. Plus you may have to edit files named like cron.deny or cron.allow depending on what you a really trying to do.
# 5  
Old 10-31-2010
Quote:
Originally Posted by jim mcnamara
What OS do you have? -- simply using at will start a job, but you have to give it offset times, and those vary a little by OS. Plus you may have to edit files named like cron.deny or cron.allow depending on what you a really trying to do.
I have Ubuntu 10.10..I have a half solution..lol
This is the commant on crontab for randomly hour once a day
Code:
*/n * * * * /usr/local/bin/php /home/user/domain.com/cron.php >/dev/null 2>&1(registrations on)

for openning registrations..But I need one cron job more to stop the previus (to change the config file again in normal mode after 1 hour--registrations off--)
I m trying with this php cron script but is not correct..Please help me with this script
Code:
<?
    set_time_limit(0);
    sleep(rand(0, 86400));
    /*
  my spesify code here
    */

    ?>

Thank you in advance

Last edited by Scott; 10-31-2010 at 02:11 PM.. Reason: Code tags
# 6  
Old 11-01-2010
You can simply generate a random number each day (with one crontab file that runs only once at the beginning of the day) that corresponds to the number of minutes (or 5 minute intervals) each day, and write that number to a file.

Then, you have a second crontab file that reads the random number in the file and checks against the time and executes if there is match.

If you are using PHP, you can also try to use PHP shared memory, or you could use an environmental variable to hold the daily random number. There are many ways to do this.

---------- Post updated at 04:38 ---------- Previous update was at 04:34 ----------

Quote:
Originally Posted by ctsgnb
maybe use the "at" command instead ?
While it is possible to set something up with the at command, the original poster asked for a crontab solution.

This is easily done with cron, as requested by the original poster.

(See my post above)
# 7  
Old 11-01-2010
Bug Cron job randomly once a day

nice thinking...Thank you ..But i m noob...Lets see
At first I will create one crontab like this
Code:
*/n * * * * /usr/local/bin/php /home/user/domain.com/cron.php >/dev/null 2>&1 /tmp/regon.log(registrations on)

What is the next crontab to check this file..I do not know..Which is the cron command to spy this file and calculate one hour????.Please give me an example..Thank you...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

AIX cron job is running everyday instead of on a particular day

Hello, I was trying to run a script on a dev server using cron job. It supposed to run 3rd sunday of every month. 45 4 15-21 * 0 /home/user1/myscript.sh >/dev/null 2>&1 # run this script 3rd sunday of every month When I Schedule it on AIX server, It is running every day at 4:45 AM. am I... (3 Replies)
Discussion started by: Kumar7997
3 Replies

2. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

3. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

4. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

5. UNIX for Dummies Questions & Answers

How to Disabling cron for few hours each day

Hi Is there any way to disable cron adhoc ? I want to run a script for every one minute between 04 to 00 hours will the below serves my purpose ? 01 04-00 * * * <your script> (1 Reply)
Discussion started by: rakeshkumar
1 Replies

6. UNIX for Advanced & Expert Users

Run A Job in Cron On A Specific Day Excluding Holidays

Hi, I want to run a job in cron on a specific date(say 25th of every month) excluding holidays. Can anyone provide some hints to do this? Thanks for any inputs. (1 Reply)
Discussion started by: sktkpl
1 Replies

7. Shell Programming and Scripting

Autosys job scheduling on specific day

Below is the requirement i am trying to do using auto sysjob. I need to create a JOB or script which will do the below things for me I have a box and there corresponding jobs as below BOX_1 JOB_1 JOB_2 BOX_2--- SU(JOB_2), this will run only on completion (Success) of JOB_2 ... (2 Replies)
Discussion started by: j_panky
2 Replies

8. UNIX for Advanced & Expert Users

Autosys Job Running every 5th Day of Month

Hi, Is there a way to schedule a job in Autosys to run every 5th Day of Month without using custom calendar? Thanks. (1 Reply)
Discussion started by: vbhatnag
1 Replies

9. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

10. UNIX for Dummies Questions & Answers

CRON usage for CRON job

can anybody explain the usage of CRON for adding a cron job. please provide an example also for better understanding !!! Thanks (1 Reply)
Discussion started by: skyineyes
1 Replies
Login or Register to Ask a Question