Koozali.org: home of the SME Server
Legacy Forums => General Discussion (Legacy) => Topic started by: silasp on November 01, 2005, 02:57:00 AM
-
Hi folks.
Call me captain obvious, but I've just figured out how to work cron / crontab in SME server and I'd like to share the info with the world. Maybe it will save someone some time?
There's a userpanel crontab manager available here:
http://www.vanhees.cc/modules.php?op=modload&name=Downloads&file=index&req=viewsdownload
But if you want to create more detailed cron jobs - ie one that runs every 5 minutes, then read on...
Create a new file in /etc/cron.d/ :
pico /etc/crond/newfile.cron
Then insert some lines in the textfile that correspond to the options that you want:
The format of the crontab file is as follows:
Minute(0-59) Hour(0-23) Day of Month(1-31) Month(1-12 or Jan-Dec) Day of Week(0-6 or Sun-Sat) User Command
You can use x,y,z to specify multiple options of the same time unit.
You can use * to specify all.
You can use */x format (see examples for explanation of how this works)
eg:
59 17 1,10,20,30 * * root /home/username/backupsite
This would execute the task on the 1st, the 10th, the 20th and on the 30th of each month, at 17:59PM.
59 17 * * 1-5 root /home/username/backupsite
This would execute the cron job on weekdays only.
59 */6 * * * root /home/username/backupsite
Here, the tasks is executed every 4 hours (24/6 =4).
(thanks to http://www.clockwatchers.com/cron_advanced.html for examples)
So, add the lines to your newfile.cron file with pico and save it.
Now, you have to execute the following command to integrate it into the crontab manager:
crontab -u root /etc/cron.d/
And that's it!
Cheers,
Silas.
-
Or do this:
mkdir -p /etc/e-smith/templates-custom/etc/crontab/your_file_name
pico -w /etc/e-smith/templates-custom/etc/crontab/your_file_name
add your cron entries
/sbin/e-smith/expand-template etc/crontab
more /etc/crontab - just to verify your new entry is there, then
/etc/e-smith/events/actions/restart-crond
JB
-
Thanks JB - that is the proper e-smith template way to do things.
People reading this thread might also be curious as to how to call PHP pages from a cron job.
With SME server, the quickest (but dirtiest way) is to add a cron entry something like this:
0 6 * * 1-5 root wget 192.168.1.1/ibay_name/webpage.php; rm -f webpage.php
The above example will execute the page at http://192.168.1.1/ibay_name/webpage.php
at 6:00 AM on Mon-Fri.
The 'proper' way to call PHP scripts on your own server from cron is to set it up to work as a command-line service, but I have no idea how to do this.
The above method should also work with external web sites.
Cheers,
Silas.
-
Or do this:
mkdir -p /etc/e-smith/templates-custom/etc/crontab/your_file_name
pico -w /etc/e-smith/templates-custom/etc/crontab/your_file_name
add your cron entries
/sbin/e-smith/expand-template etc/crontab
more /etc/crontab - just to verify your new entry is there, then
/etc/e-smith/events/actions/restart-crond
JB
Pico states that you cannot write the file because it is a directory.
Please explain why this is.
Thanks
Carl
-
The first line should be...
mkdir -p /etc/e-smith/templates-custom/etc/crontab
-
Has anyone managed or is interested in creating such an add-on?
Also, the DHCP manager contirb was a greaqt tool - is it also avai;lable for SME 7?