crontab

A Linux crontab mail command example

Here's the source code for a really simple Linux mail script that I used to send an email message to one of my co-workers every month. This script used the Unix or Linux mail command to email a file to her that showed a list of all the websites on our server that she needed to bill our customers for.

Here's the source code for this simple Linux mail shell script:

Linux "crontab every" examples

I've posted other Unix and Linux crontab tutorials here before (How to edit your Linux crontab file, Example Linux crontab file format), but I've never included a tutorial that covers the "crontab every" options, as in how to run a crontab command every minute, or every hour, or every day.

To that end, here are some quick "crontab every" example entries that show the syntax for these crontab commands.

Linux crontab man page (crontab file format, section 5)

This page shows the contents of the Linux crontab man page that deals with the crontab file format (syntax), or as it says in the man page, "crontab - tables for driving cron". This crontab man page output was created on a CentOS Linux system.

You can see this same crontab man page output by entering this command on your own Linux system:

Edit your crontab file with crontab -e

I was working with an experienced Linux sysadmin a few days ago, and when we needed to make a change to the root crontab file, I was really surprised to watch him cd to the root user's crontab folder, make changes to the file, then do a kill -HUP on the crontab process.

Thinking he knew something I didn't know, I asked him why he did all of that work instead of just entering this:

Example Linux crontab file

I have a hard time remembering the crontab file format, so I thought I'd share an example crontab file here today. This is the root crontab file from a CentOS Linux server, specifically a server I use in a test environment.

Securing the Drupal cron.php script

I don't know how big of a deal it is yet, but as I learn more about Drupal and security, I just tightened down access to the Drupal cron.php script on this site.

One thing Drupal does is make a "cron" script available off of your root URL, and by default that script is made publicly available. I don't know exactly how this works yet (other than knowing that it fires off several Drupal cleanup tasks), but I really don't want to make that URL publicly available, so after digging around I found this nice Apache configuration solution here:

Linux crontab man page (crontab command)

This page shows the contents of the Linux crontab man page. This crontab output was created on a CentOS Linux system.

You can see this same crontab man page output by entering this command on your own Linux system:

man crontab

AppleScript timer - run a script on a schedule with cron

Once you know that you can run an AppleScript program from the Unix command line it's easy to run it at scheduled intervals using the Unix cron facility. Here's an example of how to run my Safari script at the 7:30 a.m. every day.

30 7 * * * /Users/al/tmp/OpenUrls.scpt

I'm not going to get into the cron facility in any detail here, I just wanted to show how this is done. I will say that I modify the cron script by using this command:

How do I get crontab started running when using cygwin?

I can't remember where I found it, but using this series of commands from the cygwin prompt got the crontab system enabled for me. First this command:

Linux crontab example - run a program as another user

Assuming you are the root user on a Linux computer, here's a quick example of how to run a program with a Linux crontab entry as another user. Specifically in this example, the program being executed is run as the user nobody.

Syndicate content