Troubleshooting: crontab not running

The main objective of the “crontab” is to schedule the defined commands to execute periodically at the specified time interval. The “Crontab” file can be created, modified, deleted, and viewed using the “Crontab” command. Before the execution of the crontab first, the user activates the crontab services. Sometimes these services are inactive and can’t run or execute the cron job 

This post explains why and solutions for the problem “crontab” is not running. The outline of this post is specified below:

Let’s start with the reasons for this problem.

Reason 1: Cron Daemon is not Active

The “Crontab” uses a “cron” daemon that runs in the background to check whether any scheduled jobs need to be executed. One of the most popular reasons for this error is the “cron” daemon is not working properly, or its services are “inactive”.

To check it use the below-mentioned command in the terminal (Ctrl+Alt+T):

$ sudo systemctl status cron

The output displays that the “crontab” daemon is “inactive(dead)”

Solution 1: Activate the Cron Service

The possible solution for this error is to activate or start the “crontab” service by executing the following command:

$ sudo systemctl start cron

The green indicator displays that the “crontab” service is activated. It is verified by again running the above “status” command.

Reason 2: Incorrect Script

The next possible solution is missing the necessary parameters in a defined script that will be created to run as a cron job. Suppose the “shebang #!” the essential character sequence is not defined in the script as it is the first line that executes the interpreter by following its absolute path:

$ nano script.sh

Solution 2: Correct Script

Define the “Shebang #!” in the above “script.sh” script to execute or run the desired cron job properly in the “bash” shell or any other as per requirement:

$ nano script.sh

Reason 3: Lack of Permissions

The “crontab” is not working correctly, as if the created cron job script does not have the execute permissions. It displays the error at the time of execution like this:

$ ./script.sh

Solution 3: Allow the Permissions

Make the “script.sh” executable as a cron job at the specified time interval for all the Linux users by using the “chmod” command with “x (execute)” permission:

$ chmod +x script.sh

The “script.sh” script is executed successfully, as shown in the above image.

Reason 4: Invalid Path of Cron Job

During adding a particular cron job in the crontab file, ensure that the defined script’s absolute path is correct or valid.

As the user wants to execute the “script.sh” in the “home” directory but in the “crontab” file the absolute path contains the invalid target directory “test” directory:

$ crontab -e

Solution 4: Valid Path of cron Job

Type the absolute path of the script “script.sh” script where it will execute at the defined time sequence that is every hour as shown in the screenshot:

$ crontab -e

Note:

  • Environment Variables are not Set: Another possible solution is that the system environment variables are not set properly according to its valid format.
  • Missing the File extension: Same as the invalid path if the user doesn’t use the exact file extension such as “.txt” then the crontab is not running

That’s all about the reason and solutions of “crontab” not running.

Conclusion

The most feasible solution to the error “crontab” is not running is to activate/enable the “crontab” service. The error occurs due to the “invalid path of the script”, “missing the essential parameters”, “missing the file extension”, and “lack of permissions”. This post has provided all the possible reasons and working solutions to the error “crontab” not running.