Koozali.org: home of the SME Server

Ultimate cron / crontab guide in SME server.

silasp

Ultimate cron / crontab guide in SME server.
« 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/ :

Code: [Select]
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:
Code: [Select]
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.

Code: [Select]
59 17 * * 1-5 root /home/username/backupsite
This would execute the cron job on weekdays only.

Code: [Select]
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:
Code: [Select]
crontab -u root /etc/cron.d/

And that's it!
Cheers,
Silas.

Offline mrjhb3

  • *
  • 1,188
  • +0/-0
    • John Bennett Services
Ultimate cron / crontab guide in SME server.
« Reply #1 on: November 01, 2005, 04:17:09 AM »
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
......

silasp

Call PHP pages from Cron / Crontab entries.
« Reply #2 on: December 02, 2005, 02:19:37 AM »
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.

Offline cbacani

  • *
  • 111
  • +0/-0
Doesn't Work
« Reply #3 on: February 03, 2007, 12:22:30 PM »
Quote from: "mrjhb3"
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

Offline william_syd

  • ****
  • 1,608
  • +0/-0
  • Nothing to see here.
    • http://www.magicwilly.info
Ultimate cron / crontab guide in SME server.
« Reply #4 on: February 03, 2007, 02:42:01 PM »
The first line should be...

Code: [Select]
mkdir -p /etc/e-smith/templates-custom/etc/crontab
Regards,
William

IF I give advise.. It's only if it was me....

Offline nigeltodd

  • ***
  • 82
  • +0/-0
    • http://nigelt.dyndns.org
crontab panel for SME 7?
« Reply #5 on: July 23, 2007, 01:38:13 PM »
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?
smoke-free since June 24th, 2004............