Cron is a popular tool used in Unix-like operating systems to schedule jobs or commands to run automatically at specific intervals. The crontab command is used to create, edit, and delete cron jobs. However, if you get an error message that says “-bash: crontab: command not found”, it means that the crontab command is not installed or not in the system’s PATH.
[root@server ~]# crontab -l -bash: crontab: command not found [root@server ~]# crontab -e -bash: crontab: command not found
In this guide, we will show you how to fix this error.
Step 1: Check crontab installation
The first step is to check if the crontab command is installed on your system. You can do this by running the following command:
which crontab
If the crontab command is installed, you will see the path to the crontab executable. If the command is not installed, you will see no output.
Step 2: Install cronie
If the crontab command is not installed, you need to install the cronie package. You can do this by running the following command as root:
yum install cronie
This will download and install the cronie package and its dependencies.
Step 3: Verify crontab installation
After installing cronie, you need to verify that the crontab command is now available. You can do this by running the which command again:
which crontab
If the installation was successful, you will see the path to the crontab executable.
Step 4: Add crontab to PATH
If the crontab command is still not available, you need to add the directory containing the crontab executable to the system’s PATH environment variable. You can do this by adding the following line to the /etc/profile file:
export PATH=$PATH:/usr/sbin
Save the file and exit the text editor.
Step 5: Reload profile
After adding the PATH variable, you need to reload the /etc/profile file to apply the changes. You can do this by running the following command:
source /etc/profile
Step 6: Verify crontab availability
Finally, you can verify that the crontab command is now available by running the which command again:
which crontab
If the command is available, you will see the path to the crontab executable.
Commands Mentioned:
- which – locates the executable file of a command
- yum install – installs packages
- source – reloads shell environment
Conclusion:
In this guide, we have shown you how to fix the “-bash: crontab: command not found” error by installing the cronie package or adding the crontab directory to the system’s PATH environment variable. By fixing this error, you can now use the crontab command to schedule jobs or commands to run automatically.