- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to test a weekly crontab job on Linux?
In order to test a crontab job we first need to explore and understand what a crontab job is.
A crontab job is nothing but a list of commands that we can run during a cron job. A cron job is a utility that schedules automatic execution of commands at specific times.
We can start a cron job with the help of bash script by following the commands shown below −
This will open a file which you can edit, insert the cron job shell script in the above file and then close that file.
Just insert the code shown below in the above file
* * * * * sample.sh
The above command contains 5 *, where each * indicates the time and then follows the stars. We have the script which we want to run as a cron job. In the sample.sh
we need to write the following command to make the environment variables available to it.
One way to test a weekly cron job is to make use of a lock file that when used will set the cron job to run every minute. This way you can keep editing the files and each minute these files will be tested and you will be aware if your cron job is working properly or not.
Just create a shell script for the same inside which you can place your cron job.
The shell script is shown below −
#!/bin/sh if [ -e /tmp/lock ] then echo "cronjob locked" exit 1 fi touch /tmp/lock <..do your regular cron here ...> rm -f /tmp/lock
An alternate way is to make use of the /var/log directory and then run the following command shown below −
The above command will allow you to check the cron log updates in real time.
- How to run a crontab job every week on Sunday?
- Crontab day of the week syntax on Linux
- How to Run a Cron Job Every Day on a Linux System
- The Linux Job Market
- How would I get a cron job to run every 30 minutes on Linux?
- How to Create a Cron Job and Execute at a Given Time in Linux
- How to Test your Broadband Speed from Linux Terminal
- How to invert a grep expression on Linux?
- How to Install Git on Linux
- How to activate virtualenv on Linux?
- How to disable a TestNG test based on a condition?
- How to decode a job advertisement?
- How to download a website page on Linux terminal?
- How to Format a Hard Disk on Linux OS
- How to set a proxy for wget on Linux?