Current location: Hot Scripts Forums » Programming Languages » PHP » Global Arrays and crontab


Global Arrays and crontab

Reply
  #1 (permalink)  
Old 11-24-05, 07:32 PM
johnnytalent johnnytalent is offline
New Member
 
Join Date: Nov 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Global Arrays and crontab

Can someone that maybe has a couple minutes, help me out with setting up 3 cron jobs on my server, and help me to fix my global arrays on my hosted script. I know that this is not a hard job, but I am new to this whole thing. The script recommends 3 different cron jobs, and I am not certaing if I have the paths written correctly. As far as the global arrays go, I don't know where to change them at. Please Help me!! I spent 4 hours starting the catagories on my directory site only to find this out. I have many scripts to offer if you are interested. You can either email me at the addy in my profile, or ICQ me at:269272761 Thanks.
Reply With Quote
  #2 (permalink)  
Old 11-24-05, 11:23 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by johnnytalent
Can someone that maybe has a couple minutes, help me out with setting up 3 cron jobs on my server, and help me to fix my global arrays on my hosted script.
I can give you the lines needed to run the cron jobs if you can tell me when and how often they're supposed to run. I've also pasted in a cron tutorial that may be of use.

---------------------------------------------------------------------
Crontab is like an alarm clock and a task scheduler. It's just a text file you create on your webserver. The crontab file looks like this (below)

0 * * * * /etc/reset.cgi
0 0 * * * /etc/resetlogs.cgi

So what does this mean? Very simple. In this example we have a crontab file that contains 2 commands. A crontab file can have any number of commands.

You put one command per line so [ 0 * * * * * /etc/reset.cgi ] is COMMAND ONE and [ 0 0 * * * /etc/resetlogs.cgi ] is COMMAND TWO. I could have COMMAND THREE - COMMAND 2,000 if I wanted to but what is important is you only put ONE COMMAND PER LINE. Also EVEN MORE IMPORTANT after the LAST COMMAND you MUST HAVE A BLANK LINE or CRONTAB WILL NOT RUN.

Ok, so let's look at each command. Here is what we have - very simple just remember this is just like setting an alarm clock. Each line or COMMAND is SCHEDULED to run at a specific time. The first 5 fields deal with setting the time the command (second field) will run.

0 * * * * is the SCHEDULE for COMMAND ONE [ /etc/reset.cgi]
0 0 * * * is the SCHEDULE for COMMAND TWO [ /etc/resetlogs.cgi]

The way the schedule looks is very cryptic but its really very simple. There are FIVE fields to the SCHEDULE
MINUTE(0-59) HOUR(0-23) DAYOFMONTH(1-31) MONTHOFYEAR(1-12) DAYOFWEEK(0-6) Note 0 = Sun

Also note that the ASTERISK (*) is what's called a WILDCARD meaning it will match any value.

Now maybe its a little clearer: The first command of our example

0 * * * * /etc/reset.cgi

Means literally "execute the script located at /etc/reset.cgi whenever the clock is equal to 0 minutes on ANYDAY, ANY HOUR,ANY DAYOFMONTH,ANY DAYOFWEEK. So the script is set to run ONCE PER HOUR EXACTLY ON THE HOUR regardless of what day it is or what hour.

Now the SECOND COMMAND

0 0 * * * /etc/resetlogs.cgi

is a little more picky. This crontab runs again whenever the internal clock hits ZERO (0) Minutes, but instead of running once per minute it will only run once per day. WHY? Because we also set the HOUR to zero so BOTH the MINUTES and HOUR must be equal to zero before crontab will execute /etc/resetlogs.cgi. So this example runs once per DAY at MIDNIGHT server time.

Now, you can get even more picky, final example lets setup a crontab to run only on Tuesday at 2:21 PM.
MIN = 21
HOUR = 14 (ah ha! note we are in a computer - only understands military time)
DAYOFMONTH = * (who cares as long as its on a Tuesday)
MONTHOFYEAR = * (again we don't care)
DAYOFWEEK = 2 (sun=0, mon=1, tue=2)
So our crontab entry would be

21 14 * * 2 /path/to/whatever/script.cgi

UPLOADING AND EXECUTING CRONTAB(s)
It does not matter what you call your crontab file. You should name it something so you remember what the file is (eg: cronstats or croncgi) or whatever.

Upload as ASCII file. When you are done with all that telnet into your server and run the crontab file by going to the directory containing the crontab file (again - it makes no difference where you put the crontab file). I would suggest making a special hidden directory or using a directory inside your cgi-bin so nobody can see it. So to finish and execute your crontab file just telnet into your server and type:

cd /path/to/crontab/directory

crontab nameofcrontabfile
================================================== ===========
Examples:

*/15 * * * * cp -f /dev/null /var/log/cgi.log
Copies /dev/null to the /var/log/cgi.log file every 15 minutes. This empties the file but doesn't delete it.

0,15,30,45 * * * * /usr/bin/foo
Will run /usr/bin/foo every 15 minutes on every hour, day-of-month, month, and day-of-week. In other words, it will run every 15 minutes for as long as the machine it running.

10 3 * * * /usr/bin/foo
Will run /usr/bin/foo at 3:10am on every day.

10 * 1 * * /usr/bin/foo
Will run /usr/bin/foo at 12:10am on the first day of the month.

10 * * 1 * /usr/bin/foo
Will run /usr/bin/foo at 12:10am on the first month of the year.

10 14 * * 1 /usr/bin/foo
Will run /usr/bin/foo at 2:10pm on every Monday.

There are more options for these. See man man crontab -S 5.
You must use crontab to load cron jobs into cron. First create a text file that uses the above rule to describe the cron job that you want to load into cron. But before you load it, type crontab -l to list any jobs that are currently loaded in crontab.

If none are listed, then it is safe to load your job. Example. If you wanted to run /usr/local/bin/foo once a day at 3:10am, then create a text file

10 3 * * * /usr/bin/foo

Save it as foo.cron. Then type crontab foo.cron. Check to see if it was loaded by typing crontab -l. It should display something like this:

# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (ipwatch.cron installed on Thu Nov 18 11:48:02 1999)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
10 3 * * * /usr/bin/foo

If you want to edit the cron job, then edit foo.cron and then remove the existing cron job (crontab -r) and load it again (crontab foo.cron). You can have multiple jobs. Just put each different one on a seperate line in foo.cron.

Note that crontab jobs will run under the user that was in effect when you loaded the job in crontab.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #3 (permalink)  
Old 11-25-05, 08:11 AM
johnnytalent johnnytalent is offline
New Member
 
Join Date: Nov 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you

Your post was very detailed and useful. My host has an option to where you can set up cron jobs, and it's very quite simple. The problem I am having is not knowing how specific to be on my file path. This is what the manual says:


The script will deliver e-mail notifications on new or updated listings to members that have subscribed to receive them. Setting up this script requires crontab. It's an optional script, so if you don't want this feature for your site or do not have access to crontab then skip this step.

The script is located in your installation root directory and is called send_subscriptions.php. It is recommended to rename it to something else first to avoid malicious requests, for example, rename it to send_subscriptions_123.php or similar style. Now that's actually a really simple thing to do. Open your favourite cron manager and set up to execute

path/to/php path/to/notification/delivery/script
Typical example: /usr/bin/php /home/mydomain/public_html/send_subscriptions_123.php

The script has to be executed every 24 hours to deliver notifications once daily.


So If the actual "send subscriptions" file is not right under the public_html directory. Say you would have to go into two more files to get it. I would have to be that specific in order to have the correct path, right? The thing is, that I paid someone to set this up, and they messed it up. I have three subdomains in the public_html folder, and this script is also in a seperate folder. I wanted this script to be the main domain, so if I wanted it to be the main domain, I should have had it installed directly into the public_html folder by itself, right? It should have not been installed under one folder under public_html, then another. Right now my url is my domain/afolder/another folder. I had to set up a redirect in order to get it so that a user types in my url, and it redirects them to my page. This is why I paid someone to do it, because I am not to familiar with script at all. About the cron jobs, I think that may be the reason that my links are not updating the way they should for 1, and the information on my page that gives you the total # of links in the total # of catagories is also wrong. I would really like to get these problems fixed, so If someone can help, they will be paid to do it. I know that these are relatively small flaws to fix however, I need them to be done. If someone is interested, please let me know. Thank you.
Reply With Quote
  #4 (permalink)  
Old 11-25-05, 09:59 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by johnnytalent
So If the actual "send subscriptions" file is not right under the public_html directory. Say you would have to go into two more files to get it. I would have to be that specific in order to have the correct path, right?
I believe that's correct if you mean directiories instead of files.


Quote:
Originally Posted by johnnytalent
The thing is, that I paid someone to set this up, and they messed it up. I have three subdomains in the public_html folder, and this script is also in a seperate folder. I wanted this script to be the main domain, so if I wanted it to be the main domain, I should have had it installed directly into the public_html folder by itself, right? It should have not been installed under one folder under public_html, then another.
It shouldn't really make much difference, you should just need to specify the path in crontab correctly regardless of where the script is located.


Quote:
Originally Posted by johnnytalent
If someone can help, they will be paid to do it. I know that these are relatively small flaws to fix however, I need them to be done. If someone is interested, please let me know. Thank you.
I can have a look and see what needs to be done. More than likely it would be some fairly simple changes. If it's not a huge deal to fix it then there wouldn't be any need to pay me. Send me a PM if you want me to take a look at it and we'll go from there.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 06:21 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.