home resources search newsjoinmembers: 6963
PHP Flash Java Ruby Windows Linux
Hiveminds's picture

Hiveminds | Tue, 2006-05-30 11:00  tags: ,

Tutorial

Finding out how to do crontab or any other Unix work on in a Windows environment is like pulling short hairs out with your fingers tips. But I finally found some instruction that worked.

Having been spoiled by Direct Admin and other Control panels with crontab built in I was horrified by the fact that Dreamhost does not provide an interface for doing this simply. But if it is a trade for having shell access then I will take shell access. I avoided commandline crontab and Linux editors because they just take too much time and always seem to be buggy on Windows. After spending a whole day in Nano and Putty I finally got a cronjob placed on the server. But then upon going back to change things Nano and Putty failed. I could not update the crontab file. Luckily there is more ways to skin this cat. You can upload a text file and using Putty have crontab scan it for input.

So now I can get to work on creating those demo sites in Drupal, Joomla and Wordpress that will have resets on the database. Demos for these CMS at opensourcecms.com bug me because they are empty. You cannot get a feel for the CMS this way. Joomla now has nice dummy filler as does Wordpress. Drupal needs to do the same. It does not require a insatller to have good dummy text and users. But anyway back to crontab.

The crontabcommands

The crontab files are not generated by editing a the crontab file in the crontab spool directory, instead the command crontab is used to edit, list, create or remove a crontab file for a user. The crontab command can be used by all the users on a system to create personal crontab as well as by the root account. Users are not allowed to view, edit or create crontab files for other users. Basic commands:

crontab -e

The edit option crontab -e for the crontab command copies or creates the current user's crontab file. After editing is complete, the file is installed as the user's crontab file in the crontab spool directory.

crontab -l

The list option, crontab -l, displays the contents of the current user's crontab file.

crontab -r

The remove option, crontab -r, empties the contents of the current user's crontab file.

Quick Crontab Editing:

The first step is to open a local text editor (such as, write, bbedit, etc).

Switch OFF word wrap if it has this feature.

Next, type in the commands.

The example below executes a web browser call to page cron.php, every 15 minutes.

00 * * * * wget -q -O /dev/null -nd http://website.com/services/reminders/cron.php
15 * * * * wget -q -O /dev/null -nd http://website.com/services/reminders/cron.php
30 * * * * wget -q -O /dev/null -nd http://website.com/services/reminders/cron.php
45 * * * * wget -q -O /dev/null -nd http://website.com/services/reminders/cron.php

Now press return again so you have a blank line at the bottom. THIS IS
VERY IMPORTANT!

  1. Save the file as a text file, such as, mycron.txt
  2. FTP to your account, and upload this file as type text to your /home/vs#####
    directory.
  3. Now telnet to your account and at the command prompt type

    crontab -l       (note lowercase
    L )

    crontab mycron.txt 





Now, try crontab -l again.

Congratulations. You've created your first crontab!

Example used with log files:

Create a text file with the example contents below, edit as necessary and
upload to home directory (crontab executes it, see below):

#!/bin/sh 
cp vs00000.access.log vs00000.access_old.log
cp empty.file vs00000.access.log
cp vs00000.error.log vs00000.error_old.log
cp empty.file vs00000.error.log

 

Set permissions of this shell script file to 755.

Then include this line (modify the vs00000 info) in the crontab file:

01 00 * * mon /home/vs00000/shell_script_file_name



Happy Publishing!

Hiveminds's picture
This article brought to you by the Hiveminds Magazine - Staff. Contact us if you want to post an article or announcement anonymously
a Visitor posted on: Sat, 2008-03-15 02:26.

hi,

in regard to step 2.:

"FTP to your account, and upload this file as type text to your /home/vs#####
directory."

what is dir /vs#### ? i am not using dreamhost but a hosting site called 1and1.com, which doesn't use Cpanel, so you need to use SSH/putty, which i have never been successful with. (for cronjobs or anything else for that matter :-(

thanx in advance,

alex alaska p.

Hiveminds posted on: Sat, 2008-03-15 07:29.

You want to upload to the root directory for your 1 and 1 account. Something like /home/user/your_account/....

a Visitor posted on: Sun, 2008-03-16 00:58.

hey all,

i know how to set a cron job when it comes to starting an event "at a particular time on a particular date." BUT how do i set up a sequence where a "maximum time limit of 10 minutes is given for an autoresponder email to respond to a form submission" (for any hour of any day of any month etc? or should i say "every" hour...etc.)

thanx in advance,

a.a.p.

Hiveminds posted on: Sun, 2008-03-16 10:14.

PHP does not support multi-threading in the way that you would need to use it to accomplish this. The best you can hope for is to fake it by creating one script to listen to another or several scripts. For instance you could set the timeout for the autoresponder script to 10 minutes and then have a listener script check on the process markers every 2 minutes or so. Here's a good tut on this called multi-threading stragegies

 
CMS Comparison Matrix
 
Web Developers Drupal Web Developers Silverlight Content Management Systems Joomla!

Newsletter

Get updates on Hiveminds services, articles and downloads by signing up for the newsletter.

Editor's choice

Some of the better articles, stories and tutorials found at Hiveminds.

Find more

Find more of Hiveminds articles, stories, tutorials and user comments by searching.




Picked links

Hand picked websites and articles from around the web that provide quality reading.