Tech on Tour header image 2

Linux CRONTAB – Adding a Linux cron job

August 1st, 2007 by Alex Costa · 1 Comment


How to setup a cron job on a Linux server? I’ve designed a smal PHP aplication that administers my DHCP server and I neded to add a cron job so a script would remove computers from my MAC filtering enabled DHCP. I just set a cron job in seconds using crontab and now I don’t need to worry about removing computer from my DHCP.

It’s better if done as ROOT so after you open the shell commandline you can either use SUDO or change user by using SU (it will ask you for the ROOT user password) depending on your Linux distribution. I did mine on a Debian based distro so I’ll use SUDO for this.

1 – Open Shell Commandline
2 – type sudo crontab -e to add a new cron job
3 – add the cron job details

# Use the hash sign to prefix a comment
# +—————- minute (0 – 59)
# | +————- hour (0 – 23)
# | | +———- day of month (1 – 31)
# | | | +——- month (1 – 12)
# | | | | +—- day of week (0 – 7) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed

So lets say I want to add a cron job that runs every day at 00:00

0 0 * * * php /var/www/dhcpwebmin/clean_dhcp.php

or if I wanted to run another script at 1:05PM from April to June every Wednesday.

05 13 * 4-6 3 shell /etc/myscripts/wednesday_script.sh

4 – When finished press CTRL + o to write to the file (it will ask you to confirm by pressing ENTER)
5 – Press CTRL + x to exit

If you want to see the list of cron jobs just type on the commandline SUDO contab -l

Tags: OS & Servers

1 response so far ↓

  • 1 Linux Commands // Sep 5, 2007 at 10:42 am

    [...] used some of these commands onĀ  CRON Jobs for several different scheduled tasks I had to run on my Linux PC and on some of the servers I look [...]

Leave a Comment