Thursday, April 7, 2022

Linux Cron jobs

 Cron jobs

It is a software utility that is a time-based job scheduler in Linux. With the help of this utility, you can run commands or scripts at a given date and time.We can schedule the jobs like taking backups or move the files etc periodically with the help of cron jobs

Setup Cron jobs

Step 1: Update the apt repository

            apt update

Step 2: Check cron is already installed or not (on Ubuntu)

        dpkg -l cron

Step 3: If it is not installed then install it

      apt install cron -y

Step 4: Check the service is in a running state or not

     systemctl status cron

Step 5: create a file /home/vagrant/test.sh

      add below content

     echo `date` >> /home/vagrant/file1

Step 6: Provide execute permission to your file

     chmod 777 test.sh

Step 7: Run the below command to setup the cron job.

    crontab -e

add below entry at the bottom

  * * * * * /home/test.sh

Step 6: Wait for 1 min and you will find that test.sh script is executed








0 comments:

Post a Comment