Category Archives: Linux

Creating a crontab with just 1 command

In this tutorial you will learn, how to add a cronjob with just one command to your crontab file.
This makes deploying virtual machines and their automatic configuration of Cronjobs easy!

That is all you need! This command will be appended to your crontab files.

 

It is pretty handy for setting up cronjobs on fresh Ubuntu VMs without requiring root.

Happy Deploying!

Creating Cromjobs

What is a cronjob or a crontab file?

Crontab (cron table) is a text file that specifies the schedule of cron jobs. There are two types of crontab files. The system-wide crontab files and individual user crontab files.

Users crontab files are stored by the user’s name and their location varies by operating systems. In Red Hat based system such as CentOS, crontab files are stored in the /var/spool/cron directory while on Debian and Ubuntu files are stored in the /var/spool/cron/crontabs directory.

Although you can edit the user crontab files manually, it is recommended to use the crontab command.

/etc/crontab and the files inside the /etc/cron.d directory are system-wide crontab files which can be edited only by the system administrators.
In most Linux distributions you can also put scripts inside the /etc/cron.{hourly,daily,weekly,monthly} directories and the scripts will be executed every hour/day/week/month

Linux Crontab Command

The crontab command allows you to install or open a crontab file for editing. You can use the crontab command to view, add, remove or modify cron jobs using the following options:

  • crontab -e – Edit crontab file, or create one if it doesn’t already exist.
  • crontab -l – Display crontab file contents.
  • crontab -r – Remove your current crontab file.
  • crontab -i – Remove your current crontab file with a prompt before removal.
  • crontab -u – Edit other use crontab file. Requires system administrator privileges.