Tuesday, November 8, 2016

Job scheduling with cron (edit crontab)

Cron is a job scheduling subsystem for linux. It is used for scheduling repeating jobs. If you wish to schedule a one shot job use the at subsystem.

All users on a linux box may set up cron jobs provided they are allowed by the administrator: root. Restrictions to cron are applied by modifying a combination of /etc/cron.allow and /etc/cron.deny.

On most Linux distributions there is also a system level cron configuration, that is not covered here.

Setup

First

Using your favourite editor create a cron file with a line for each job you wish to schedule, in the format:

m h d m w command

  • m minute 
  • h hour 
  • d day of month 
  • m month 1-12 
  • w weekday 0-7, Sun,Mon, etc (Sunday = 0 = 7) 
  • command the command you want to run

It is easy to remember if you think of the way one would say a date: Wednesday, July 29, at 10:30, then reverse the order.

For example, this is new.crontab:


Second

Use crontab to load your file (this informs the cron daemon (crond) about it), note it will overwrite any existing crontab file so make sure you have everything you want.


Experts, who are not afraid of VIM

You don't need to use another file you can just use crontab -e to edit  the existing crontab.

Test cron jobs

Set up a cron job to write the date to a file in your home directory, schedule it to run every 10 minutes:

After about  20 minutes tail the file, it should have put a date stamp every 10 minutes (hour, hour+10, hour +20 etc.)

If you leave it there it will keep going FOREVER, so you may want to get rid of it: crontab -r



My original post was in wikihow: https://www.wikihow.com/Set-up-a-Crontab-File-on-Linux  Someone keeps changing the screenshots and putting up incorrect information so I moved it here.

Wednesday, February 3, 2016

Using VI

Using VIM (originally VI)  Visual Improved Text Editor


VIM or VI is the de facto text editor for all Unix systems.

This post is for those who want to learn how to use VI.  I am not going to get into VI vs Emacs or any other religious wars such as Linux vs Windows etc.  The simple fact is that any Unix box you use will have VI installed so knowing at least the basics will help you in a pinch (or when your system is floundering you can rescue it.)

Start Here

Essential Commands (short quick ref for VIM)

ESC   - change to command mode. The following commands will then work:
:q!      - quit without saving
:wq    - write changes then quit
i         - insert mode (enter text)
dd      - delete one line
yy      - copy current line
p        - paste last copied /deleted line
R       - replace until ESC is hit
r         - replace one character
/text   - locate the string text search forward in the file (then n for next)

Other VIM Resources