Core Linux

Job Scheduling In Linux

You can set any command to run at any time (or repeatedly at a set interval) by using cron. The name comes from “chronos” – the Greek word for time. If you have Linux, you’re going to have cron. Run the command “crontab” to edit or create the jobs for your user.

Crontab Syntax :-
How to set cron job :-

king-thehacker@king-thehacker:~$ crontab -e

To edit or to set a crontab entries, use crontab -e By default this will edit or set the current logged-in users crontab.(add this line in crontab)

*    *    *    *    *    /bin/uname > /dev/pts/1

  • /bin/uname is command to execute it print hostname on terminal
  • /dev/pts/1 is terminal to display output
  • tty is command to find your terminal name
  • crontab -l is command to see crontab jobs
Setting a Cron Job For the Last Day of the Month :-

king-thehacker@king-thehacker:~$ crontab -e

To edit or to set a crontab entries, use crontab -e By default this will edit or set the current logged-in users crontab.(add this line in crontab)

*    * 28-31    * * [ “$(/bin/date +\%d -d tomorrow)” = “01” ] && /bin/uname > /dev/pts/5

  • “*”   —–> every min
  • “*”   —–> every hour
  • “28-30”  —–> it will run on each of our possible end of the month dates (28-31), every month
  • “*”   —–> every month
  • “*”   —–> every day of week
  • “[ “$(/bin/date +\%d -d tomorrow)” = “01” ]”   ——> it run date +%d command it will give day like date is 2017-09-30 it give 30 -d tomorrow it will check in calender after 30 which day is coming and in our case it will give 01 and if it match with “01” then today is our last day of month and execute command
  • “&& /bin/uname > /dev/pts/5”  ——-> it will run uname command and display it output on terminal .

Thank You