Home
 

Customer Support

Search for keywords:

Browse by category:

Can I have a crontab?

Yes, just login to your shell using ssh and type:
crontab -e
That will put you in the Vi editor editing your crontab. The Vi keystrokes you need to edit your crontab are: "i" for insert, then type out your cron line following the format below for each line, then "escape" to get out of insert mode, then ":" to get a prompt, then "wq" and then "enter" and it is saved.

The form of a crontab file is:

minute hour day month weekday command

To view your crontab file, type:
crontab -l
To remove your crontab, type:
crontab -r
A perfectly good crontab might look like this:
MAILTO=yourname@yourdomain.com
41 04 * * 1 /save/whales -v
The above crontab will execute the script "whales -v" from your "/save" directory every Monday morning at 4:41AM.

The "whales" script should be executable (permissions like 700 or -rwx------). The "whales" script should also specify on the first line which interpreter you want to use like:
#!/usr/bin/perl
or
#!/usr/bin/python
If you do not specify an interpreter, then it will assume you want the script interpreted by the shell "sh". Any output from the script will be emailed to the person listed as MAILTO. The MAILTO line is optional. To preserve shared resources, we discourage setting up a crontab which runs every minute. Modwest administrators will routinely reset scheduled crons to run every 5 minutes if they are set to run more frequently.

User-Contributed Notes

add a note
rburnham -at- blennylips.com
19-Jun-2002 08:16
Beware of the line endings in DOS vs unix.  I edited the crontab and
script files on DOS (with CR/LF endings) and unix expects just the LF. 
The symptom was the error:

/bin/sh: /ping/pingMonitor.py: bad interpreter: No such file or
directory

You can find utilities dos2unix and unix2dos to do the conversion.

Cheers,
Roger Burnham

30-Jan-2003 11:34
Any output from a cron script (including stderr messages) is emailed to
your hosting account mailbox. If you do not want the mails, or the disk
space they use up, then have your cron script produce no output:

               /path/to/script &> /dev/null 

09-Apr-2003 13:42
When trying to execute "lynx" from a cron, the cron was not executing
but was instead giving errors about "no such directory
/www/vhosts/m/myaccount.com" so I created such a path, making it lead
back to my home directory with a symlink like this:

    cd /
    mkdir www
    mkdir www/vhosts
    mkdir www/vhosts/m
    cd www/vhosts/m
    ln -s ../../../ myaccount.com

where "myaccount.com" is the domain name hosted here and "m" is the 1st
letter of that domain name

18-Nov-2003 18:49
Here's a crontab that executes at 4:41AM on the 1st of each month and
deletes files in the logs directory that are more than 32 days old:

41 04 1 * * find /logs -ctime +32 -type f -exec rm -f \{\} \;

30-Aug-2007 23:49
You CAN use a backtick operator in the command argument place in a
crontab.

However, percent signs (%) in the command must be escaped with a
backslash or else they will be interpreted as a newline.

From 'man crontab':
The ??sixth?? field (the rest of the line) specifies the command to be
run. The entire command portion of the line, up to a newline or %
character, will be executed by /bin/sh or by the shell specified in the
SHELL variable of the crontab file.
Percent-signs (%) in the command, unless escaped with backslash (\),
will be changed into newline characters, and all data after the first %
will be sent to the command as standard input. There is no way to split
a single command line onto multiple lines, like the shell?s trailing
"\".

so the following is valid:

15 3 * * 0,2-6 echo `date +\%a`

and

15 3 * * 0,2-6 echo $(date +\%a)

Failure to escape the backslash will result in a cron error:

/bin/sh: -c: line 1: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 2: syntax error: unexpected end of file

add a note

Related Questions:


Why does your service seem slow?

How do I do a traceroute to diagnose network problems?

My POST to a secure form results in a blank page, the same form, or a 500 Internal Server Error.

Internet Explorer shows a blank page on an SSL website like the Control Panel or signup page.

How do I get a command prompt on my own computer?

After I install Bugzilla, I get error 403 Forbidden.

How do I install Gallery?

I am having trouble installing phpBB2

Where can I find links to 'Standards-Compliant' Web browsers?

Do you provide CVS?

How do I use a robots.txt file?

Can I use streaming media on my site?

Do you support Flash, Shockwave, Java Applets?

I installed Norton Internet Security, and now I can't see video and other multimedia.

How do I use MnogoSearch Indexer?

Do you run Linux?

Can I use a blog or other content management system?

Do you have Postgres?

Why doesn't mivascript interpret GET variables?

How do I contact my registrar?

What does everything in a Wusage report mean?

Whenever I make changes with Movable Type I get SBOX errors.

Are there any resources for dealing with comment spam in a Movable Type blog?

How Do I Add A Google Sitemap To My Website?

Do you provide SVN?

What can I do to improve Drupal's loading speed?

Browse Categories:

Getting Started, FTP, Telnet/SSH, Moving Domains, E-mail, Traffic Reports, Mailing Lists, Apache, PHP, CGI, Other Server-Side Scripting, MySQL Database, Imaging Libraries, Other Software, Billing & Terms, Control Panel, E-commerce, Pre-Sales


Tiny Modwest Logo         Copyright 2000-2008 by Modwest, Inc.          About Us    |    Blog    |    Jobs    |    Web Design    |    Contact Us