• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

Running Cron Job on Last Day of the Month

Written by Rahul, Updated on September 21, 2019

We have a detailed instruction of using crontab on Linux system. This tutorial will help you to configure cron job to run on every last day of the Month. As there is no direct option available to do it.

So, first of all, we will schedule cron on 28,28,29 and 31’st of each month. Now find if today is the last day of the month. To find it check if the next day is 01’st of next day and then only execute any command.

Below command will return the date of the next day.

date +%d -d tomorrow

Now check if tomorrow is 01.

[ "$(date +%d -d tomorrow)" = "01" ] && echo "True"

If the next day is 01 then above command will print “True” on screen. Here you can use the above script in crontab and change echo with your command.

59 23 28-31 * * [ "$(date +%d -d tomorrow)" = "01" ] && /root/script.sh

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

1 Comment

  1. Avatar Ringo Phonebone Reply
    October 5, 2020 at 10:26 pm

    All correct except that you have to escape the %d.

    59 23 28-31 * * [ “$(date +\%d -d tomorrow)” = “01” ] && /root/script.sh

Leave a Reply Cancel reply

Popular Posts

  • How To Install Python 3.9 on Ubuntu 20.04 5
  • How To Install Python 3.9 on Ubuntu 18.04 0
  • How to Use AppImage on Linux (Beginner Guide) 2
  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy