FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Using cron.

 


Helios
Basicly Cron is a Task Scheduler.
You can run any command on a specific schedule.

Cron uses CRONTAB(cron tables) to read the commands.
You can say that crontab is somekind of a database.

You can edit crontab by the crontab command and give cron commands by the cron command.

Crontab usage.
Crontab is made of fields, each field represents a specific value:

Field 1 -> Minutes (range: from 0 to 59)
Field 2 -> Hours (range: from 0 to 23)
Field 3 -> Days (range: 1-31)
Field 4 -> Months (range: 1-12)
Field 5 -> Day of the week (range: 0-6, starting from sunday)
Field 6 -> Your command.

Let's say that you want to run some script(let's anem the script.. ermm.. X.sh) every friday to sunday at 5 pm.

So your entry would be:
0 17 * 5-0 /home/user/X.sh

And let's say that we want to delete some logs every 6 month(let's begin on June) on the 3rd of the month at 1 pm:
0 13 3 6 * rm -f /home/user/deadly/logs/*.*

So you got the idea..

Now, let's make our own Crontab list and insert the 2 entries above into it and then run cron for output. (You can also modify the original crontab, but it doesn't work for me for some reason)

So we create a new file.. hmm let's call it MyCrontab.txt
And give it the 777 CHMOD to avoid some errors =P

now, insert into MyCrontab.txt your entries. For us they would be:
0 17 * 5-0 /home/user/X.sh
0 13 3 6 * rm -f /home/user/deadly/logs/*.*

and save MyCrontab.txt.

Now access your favorit terminal and use the crontab command, like this:

[user@localhost home]$ crontab MyCrontab.txt


after that you should check if the list has applyed:
[user@localhost home]$ crontab -l
0 17 * 5-0 /home/user/X.sh
0 13 3 6 * rm -f /home/user/deadly/logs/*.*

If the above was your output, that means that you're fine.

Now, about the cron output..
You can do this with 2 ways:

1. Cron will send you an eMail.
2. Cron will place the logs into a text file.

Usage:
1. In MyCrontab.txt that we've created, we place at the top:
MAILTO="xxx@xxx.xxx"

and after that we place all of the entries.

2. We add another command to our entry(ies):

0 17 * 5-0 /home/user/X.sh >> /home/user/cron/log.txt
0 13 3 6 * rm -f /home/user/deadly/logs/*.* >> /home/user/cron/log.txt

If you don't want to log, you can just ignore the >> .


That about everything I know =\
Enjoy! xD

Copyleft 2005 Helios Zepp.
Texas Al
Here is how you do scheduled backups on a directory.

Specify the time like the parent post explained. Then, put in this...

tar -czvf /home/YOURSITE/YOURARCHIVE.tgz /home/YOURSITE/DIRECTORY

Where YOURSITE is the name of your FriHost account, YOURARCHIVE is the name you want to give the tar archive, and DIRECTORY is the directory you want to back up.

The tar archive (extensions: .tar, .tar.gz, .tgz) can be opened by all non-sucky archive programs including current versions of WinZip.

You can even set it up to dynamically name the archive according to what the date and time are so you're not always overwriting the same one... but I'm too lazy/busy at the moment to figure out what shell FriHost is running and the syntax for inserting the date variable in that shell. I'm assuming it's the sh shell, though. I'll followup on that if anybody wants to know.
Helios
As you can see, cron jobs are VERY useful!

You can use them in your home desktop or in your server.
ryanh2006
I am really glad that I decided to check out these tutorials in reverse because I would never have come across this great tutorial. Thanks so much guys for sharing this great stuff with us newbies because it can really be helpful for us newbies. Thanks
Related topics

using cron jobs and scp to automate backups
Executing automated tasks without using cron jobs
how do I auto backup using cron jobs
Help In Setting Up A Cron Job
Cron Job Error Reporting

Server for Backup
How many mails can be send by a script?...
Questions about cron jobs and permissions
Cron jobs on DirectAdmin
Cron Jobs Problem.

cron jobs
which freemail you are using?
Uploading Folders using CPanel
[tutor] How to protect images without htaccess using PHP
Cron
Reply to topic    Frihost Forum Index -> Miscellaneous -> Tutorials

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.