Miscellaneouss

Fix :- Bash:crontab: Command not found on Unix/Linux or Ubuntu/Debian

Crontab is a program and need to install on system it is also used to drive the cron daemon. Each user uses their own crontab and command. As a system admin always we need to execute some commands every-time. So it’s very difficult to run these commands manually. Cron is used to execute desired command in background at scheduled time.

In this tutorial I am going to explain how we can install crontab on CentOS/Redhat/Fedora or Ubuntu/Debian.

Follow this tutorial to know more about crontab example : Top 20 Crontab Example to Schedule Task 

You will get below error if you try to execute crontab -l command on your system means there is no crontab is installed  on your system.

#crontab -l

-bash: crontab: command not found

To install crontab command you will need to install cronie packages on CentOS/Redhat/Fedora system. You can install it from yum command. Using yum command it will install required dependencies.

Install or Setup Cron on CentOS/Redhat/Fedora

Run this below command to install cronie on your RHEL System

#yum install cronie

You will get some output like below.

Loading mirror speeds from cached hostfile
epel/metalink | 4.0 kB 00:00
* base: mirror.tadu.vn
* epel: mirror.lzu.edu.cn
* extras: mirror.dhakacom.com
* updates: mirror.dhakacom.com
base | 3.7 kB 00:00
epel | 4.3 kB 00:00
epel/primary_db | 5.0 MB 00:14
extras | 3.3 kB 00:00
mysql-connectors-community | 2.5 kB 00:00
mysql-tools-community | 2.5 kB 00:00
mysql56-community | 2.5 kB 00:00
mysql56-community/primary_db | 126 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 4.1 MB 00:08
vz-base | 951 B 00:00
vz-updates | 951 B 00:00
Resolving Dependencies
--> Running transaction check
---> Package cronie.i686 0:1.4.4-16.el6_8.2 will be installed
--> Processing Dependency: dailyjobs for package: cronie-1.4.4-16.el6_8.2.i686
--> Processing Dependency: /usr/sbin/sendmail for package: cronie-1.4.4-16.el6_8.2.i686
--> Running transaction check
---> Package cronie-anacron.i686 0:1.4.4-16.el6_8.2 will be installed
--> Processing Dependency: crontabs for package: cronie-anacron-1.4.4-16.el6_8.2.i686
---> Package exim.i686 0:4.84.2-3.el6 will be installed
--> Running transaction check
---> Package crontabs.noarch 0:1.10-33.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Installing:
cronie i686 1.4.4-16.el6_8.2 updates 74 k
Installing for dependencies:
cronie-anacron i686 1.4.4-16.el6_8.2 updates 31 k
crontabs noarch 1.10-33.el6 base 10 k
exim i686 4.84.2-3.el6 epel 1.3 M

Transaction Summary
======================================================================================================================================
Install 4 Package(s)

Total download size: 1.4 M
Installed size: 4.2 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): cronie-1.4.4-16.el6_8.2.i686.rpm | 74 kB 00:01
(2/4): cronie-anacron-1.4.4-16.el6_8.2.i686.rpm | 31 kB 00:00
(3/4): crontabs-1.10-33.el6.noarch.rpm | 10 kB 00:00
(4/4): exim-4.84.2-3.el6.i686.rpm | 1.3 MB 00:10
--------------------------------------------------------------------------------------------------------------------------------------
Total 78 kB/s | 1.4 MB 00:18
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : exim-4.84.2-3.el6.i686 1/4
Installing : cronie-anacron-1.4.4-16.el6_8.2.i686 2/4
Installing : cronie-1.4.4-16.el6_8.2.i686 3/4
Installing : crontabs-1.10-33.el6.noarch 4/4
Verifying : cronie-1.4.4-16.el6_8.2.i686 1/4
Verifying : cronie-anacron-1.4.4-16.el6_8.2.i686 2/4
Verifying : crontabs-1.10-33.el6.noarch 3/4
Verifying : exim-4.84.2-3.el6.i686 4/4

Installed:
cronie.i686 0:1.4.4-16.el6_8.2

Dependency Installed:
cronie-anacron.i686 0:1.4.4-16.el6_8.2 crontabs.noarch 0:1.10-33.el6 exim.i686 0:4.84.2-3.el6

Complete!

Adding a New Cron Job in Crontab

You can add new job using crontab -e command. It will open in default editor you will need to edit it. Crons are saved in /var/spool/cront/username file. Follow this below command to add new cron job.

# crontab -e

0 3 * * * zip -r cron-all-backup.zip /var/spool/cron/crontabs/

In above example we scheduled crontabs backup everyday at 3 ‘O’ clock.

Listing all Crontab Entry or Jobs

With -l options we can list all scheduled jobs. Follow the below command to list all scheduled jobs for current logged in user.

#crontab -l

0 3 * * * zip -r cron-all-backup.zip /var/spool/cron/crontabs/
5 1 * * * /roob/scripts/daily-backup.sh

Listing Specific User’s Crontab Entry or Jobs

Follow this below command to list specific user crontab entry or jobs.

#crontab -u ram(username) -l

0 3 * * * zip -r cron-all-backup.zip /var/spool/cron/crontabs/

Install or Setup Cron on Ubuntu/Debian System

To install or setup Cron on your Ubuntu/Debian system you will need to install cron packages on Ubuntu/Debian system.

Follow these steps to setup or install cron job on Ubuntu/Debian system.

Let’s first update your system package to latest version. Follow this below command to update your current installed packages.

# apt-get update
Or
# apt-get upgrade

Check if Cron Package Installed

Run this below command to check cron package is installed or not:

# dpkg -l cron

if cron is not installed, run this below command to install it.

# apt-get install cron

Verify Cron Service is Running or not

# service cron status

Follow these below command to stop start cron service:

To Stop

# service cron stop

To Start

# service cron start

Configure Cron Job on Ubuntu/Debian

To configure cron job you need to modify /etc/crontab file using nano editor to modify this file you need sudo permission.

# nano /etc/crontab

0 3 * * * zip -r cron-all-backup.zip /var/spool/cron/crontabs/

I hope this article will be helpful to install crontab on Redhat.x and CentOs.x system.

 

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment