NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page cron job help needed

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 11-02-2005, 02:47 AM THREAD STARTER               #1 (permalink)
Senior Member
 
dotcommakers's Avatar
Join Date: Oct 2003
Location: world wide web
Posts: 2,055
dotcommakers is a splendid one to beholddotcommakers is a splendid one to beholddotcommakers is a splendid one to beholddotcommakers is a splendid one to beholddotcommakers is a splendid one to beholddotcommakers is a splendid one to beholddotcommakers is a splendid one to beholddotcommakers is a splendid one to behold
 




cron job help needed


hello

can any one help me.. how to create a cron job to execute a one special file on my server..

i am using cpanel

regards
dotcommakers is offline  
Old 11-02-2005, 02:51 AM   #2 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Moved to "Programming"

As far as your question. This may help. The site it came off of won't load (had to look at Google's cache) so I'll paste here:

Code:
Cron comes from the word chronos, the Greek word for time. Cron is a utility that can help with automating certain tasks in Linux. For example if you would like to create backups of certain files or directories each night while you are sleeping, you can use Cron to automate this. 

Cron stores it's enteries in the crontab (cron table) file. This is generally located in your /etc directory. As well, each user on your system can have their own crontab which would be stored in /var/spool/cron/. To edit a users crontab entry, simply log into your system for that particular user and type crontab -e. The default editor for the 'crontab -e' command is vi. If you are not familiar with VI you can change the default editor by running the following command export VISUAL='editor'. Of course you must replace editor with your favorite text editor (nano, pico, joe etc). Or you could always learn how to use VI ;) 

Below are 2 entries in my /etc/crontab file. The first one is used to back up my /etc directory nightly. The second entry is to run the Analog program to calculate the web server stats for linuxhelp.ca. 

12 3 * * * root tar czf /usr/local/backups/daily/etc.tar.gz /etc >> /dev/null 2>&1
52 5 * * * root /usr/local/src/analog-5.32-lh/analog >> /dev/null 2>&1

Below is a table of what each field does. 


Field	Meaning	
1	Minute (0-59)	
2	Hour (2-24)	
3	Day of month (1-31)	
4	Month (1-12, Jan, Feb, etc)	
5	Day of week (0-6) 0 = Sunday, 1 = Monday etc or Sun, Mon, etc)	
6	User that the command will run as	
7	Command to execute	

So using one of our original examples: 

12 3 * * * root tar czf /usr/local/backups/daily/etc.tar.gz /etc >> /dev/null 2>&1
This will run tar czvf /usr/local/backups/daily/etc.tar.gz /etc at 3:12am every day. The >> /dev/null 2>&1 part means to send any standard output to /dev/null (the linux trash can) and to redirect standard error (2) to the same place as the standard output (1). Basically it runs the command without any output to a terminal etc. 

Another example of a more complex entry would be: 

30 15 13 6 1 * root tar czf /usr/local/backups/daily/etc.tar.gz /etc >> /dev/null 2>&1
This will run tar czvf /usr/local/backups/daily/etc.tar.gz /etc on Monday June 13th at 3:30pm 
You could also use the following to achieve the same results 

30 15 13 Jun Mon * root tar czf /usr/local/backups/daily/etc.tar.gz /etc >> /dev/null 2>&1

If you wanted to run a command as user joey 15 minutes after every hour regardless of the date you could add the following entry: 

15 * * * * joey /usr/bin/somecommand >> /dev/null 2>&1

The astrix '*' in the example above is a wildcard meaning that cron will ignore the field. 

If you wanted to run a command every 2 hours you could enter in */2 for the hour field. This would run the specified command at 2am, 4am, 6am, 8am, 10am, 12pm, 2pm, and so on. An example of this type of entry would be: 

0 */2 * * * joey /usr/bin/somecommand >> /dev/null 2>&1

You can also use commas to specify more than one time per entry. For instance if you wanted to run a command at 15 and 30 past each hour you would enter in 15,30 for the minute field. An example of this type of entry would be: 

15,30 * * * * joey /usr/bin/somecommand >> /dev/null 2>&1

If you wanted to run a command every day at a certain time for the first week of the month you would enter in 1-7 for the day field. An example of this type of entry would be: 

15,30 */2 1-7 * * joey /usr/bin/somecommand >> /dev/null 2>&1
This would run somecommand every 2 hours at the 15's and 30's (2:15, 2:30, 4:15, 4:30 etc) for the first 7 days of the month. 

If you want cron to execute a bunch of scripts at 4:18pm every day you could put all of the scripts in one directory (for example, /home/username/cron) and add the following line to your crontab: 

18 16 * * * root run-parts /home/username/cron >> /dev/null 2>&1

If you wanted to save the output of a certain command you can replace the >> /dev/null 2>&1 with >> /home/user/somecommand.log 2>&1 

After you've added all your entries you can use the command crontab -l to list them. 

If you wanted to remove your crontab file you could run crontab -r to delete it. 

To edit a users crontab file as root you can run crontab -e -u username 

So as you can see, Cron is very configurable and is a great tool for every system administrator to automate tasks.
Eric is offline  
Old 11-02-2005, 03:11 AM   #3 (permalink)
Senior Member
 
luxinterior's Avatar
Join Date: Jul 2004
Location: Kizmiaz
Posts: 1,091
luxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of light
 



That may a bit overwhelming for a non-programmer

Found this which is a bit more direct and to the point. Hope it helps.

http://www.4webhelp.net/tutorials/misc/cpanel2.php

Lux
luxinterior is offline  
Closed Thread


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
code needed php tony84 Web Development Wanted 1 11-01-2005 09:03 AM
Advanced Perl Coder Needed NOW 170designs Programming 0 10-28-2005 09:51 PM
Link Exchange Needed! Ericsson For Sale / Advertising Board 0 10-27-2005 10:01 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 03:51 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger