Miscellaneouss

Bash:crontab: Command not found on (Redhat.x,CentOS.x) system

crontab_installation
mm
Written by Santosh Prasad

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 its 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 Redhat.x, CentOs.x, system.

You will get below error if you try to execute crontab -l command on your system means there are 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. You can install it from yum command. Using yum command it will install required dependencies.

CRONTAB INSTALLATION

#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 NEW 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 the 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 JOBS

With -l options we can list all sheduled jobs. Follow the below command to list all scheduled jobs for current 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 CRONTAB JOBS

You can also list specific user crontab jobs.

#crontab -u ram(username) -l

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. Read our another article Easy Steps to Protect Your WordPress wp-admin(Admin) URL and Mail Command Installation On Redhat, CentOS, Fedora, Ubuntu and Debian System. If you have any queries and problem please comment in comment section or you can also ask your question.

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