+ Reply to Thread
Results 1 to 2 of 2

Thread: BASH: Determine if last day of month

  1. #1
    Jordan Guest

    BASH: Determine if last day of month

    An easy way to determine if today is the last day of the month is to determine the numerical date for tomorrow. If tomorrow is "1" then you know today is the last day of the month. This holds true for months with 31 days, 30 days or for Feb. with 28.

    Code:
    #!/bin/bash
    
    MYTZ=`date | awk '{print $5}'`
    TOM=$(TZ=$MYTZ-24 date +%d)
    
    if [ $TOM == 1 ]
     then
            echo "Last Day of the month!"
            # Enter your monthly code here
    fi
    This will allow you to create a script that executes on a monthly basis.

  2. CODECALL Circuit advertisement

     
  3. #2
    Tor
    Tor is offline Programming Expert
    Join Date
    Oct 2007
    Posts
    488
    Rep Power
    0
    You could also use the /etc/cron.monthly and it will execute at the first of the month (or last, can't remember which) without you having to code for it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 01-17-2012, 01:26 AM
  2. Determine power of 2 in C
    By fayyazlodhi in forum C and C++
    Replies: 2
    Last Post: 05-01-2011, 09:14 PM
  3. How to determine his age by using 2 datepicker? using vb.net
    By hsei99 in forum Visual Basic Programming
    Replies: 0
    Last Post: 11-02-2010, 08:05 AM
  4. Replies: 3
    Last Post: 08-19-2010, 08:44 PM
  5. Determine a input
    By NicholasIT in forum C and C++
    Replies: 3
    Last Post: 07-30-2010, 02:38 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts