How to schedule a CRON job to run a scripts on Ubuntu 20.4.1
To Schedule a CRON Job to Run a Scripts on Ubuntu 20.4.1
introduction:
The Cron is a Scheduling daemon that executes tasks at specified intervals. It reads the crontab (cron tables) for predefined commands and scripts.
Installation process:
Run lsb_release command to check the installed version of OS as follows.
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
We assume that the crontab was installed on your machine. To view the installed cron job on your machine run the following command
root@linuxhelp:~# crontab -l
no crontab for root
Assign a cron job and run the following command.
root@linuxhelp:~# crontab -e
no crontab for root - using an empty one
Select an editor. To change later, run 'select-editor'.
1. /bin/nano <---- easiest
2. /usr/bin/vim.basic
3. /usr/bin/vim.tiny
4. /bin/ed
Choose 1-4 [1]: 1
15 19 * * * /bin/sh /home/Netaxis/Desktop/abc.sh
On Ubuntu based system it will ask for the editor for the first time to choose one or by default it uses the nano editor. Add the following lines, this will execute a “ abc.sh” script at 19:15PM Save and quit the file. Then create an abc.sh file on the desktop location.
root@linuxhelp:~# cd /home/Netaxis/Desktop/
root@linuxhelp:~/Desktop# vim abc.sh
The below lines will create a file named file.txt , do not forget to the make the file executable.
root@linuxhelp:~# touch /home/Netaxis/Desktop/file.txt
root@linuxhelp:~/Desktop# chmod u+x abc.sh
with this method scheduling a CRON job to run a scripts on Ubuntu 20.4.1 comes to end.