Get 1st date of month, week , quarter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get 1st date of month, week , quarter
# 1  
Old 11-27-2013
Get 1st date of month, week , quarter

Hi ,

I need to trigger few jobs based on the system date ( in case user is not passing any date to the script. In case passing then need to take the user date).

Here is the requirement

1. Everyday call daily script
2. On 1st day of week call weekly script
3. On 1st day of month call Monthly script
4. On 1st day of the Quarter call Quarter script.

Now I need advice of you experts on how to do this.

What I was thinking is like creating a function and return some value and based on that trigger the jobs.

what do you guys suggest?
# 2  
Old 11-27-2013
What is the starting day of the week?

So, the monthly and quarterly job will be triggerred if it is 1/1 correct?

How do you define the quarters?
# 3  
Old 11-27-2013
How about this function:

Code:
function period
{
   date=${1:today}

   case "$(date -d "$date" +"%d.%m.%u")" in
       01.0[148]*|01.12*) echo "QTR" ;;
       01*) echo "MTH" ;;
       *1) echo "WK" ;;
       *) echo "NONE" ;;
   esac
}

period "Apr 1 2013"
period "Feb 1 2013"
period "Nov 11 2013"
period

Output:
Code:
QTR
MTH
WK
NONE

# 4  
Old 11-27-2013
Quote:
Originally Posted by PikK45
What is the starting day of the week?

So, the monthly and quarterly job will be triggerred if it is 1/1 correct?

How do you define the quarters?
"starting day of the week" - Monday
"monthly and quarterly job will be triggerred if it is 1/1" -- Monthly Job will be triggered on 1st day of the month, total 12 times in a year. Quaterly job will be triggered 4 times in a year. 1st-Jan, 1st- April, 1st-July, 1st-October.

---------- Post updated at 02:06 PM ---------- Previous update was at 02:05 PM ----------

Quote:
Originally Posted by Chubler_XL
How about this function:

Code:
function period
{
   date=${1:today}

   case "$(date -d "$date" +"%d.%m.%u")" in
       01.0[148]*|01.12*) echo "QTR" ;;
       01*) echo "MTH" ;;
       *1) echo "WK" ;;
       *) echo "NONE" ;;
   esac
}

period "Apr 1 2013"
period "Feb 1 2013"
period "Nov 11 2013"
period

Output:
Code:
QTR
MTH
WK
NONE


Thank you for the function.

But isn't this will run only once?
For example on 1st of the month both the daily and monthly job should be triggered. In case it's a week start as well then weekly job too. And if it's a quarter start then quarter job too.
# 5  
Old 11-27-2013
This should be closer - replace the echo statements with call to your processing function/script:

Code:
function period
{
   date=${1:today}
   period="$(date -d "$date" +"%d.%m.%u")"
   [[ $period = 01.0[147]* || $period = 01.10* ]] && echo "QTR"
   [[ $period = 01* ]] && echo "MTH"
   [[ "$period" = *.1 ]] && echo "WK"
}

period "Dec 1 2013"
echo
period "Apr 1 2013"
echo
period "Nov 11 2013"
echo
period

output:
Code:
MTH

QTR
MTH
WK

WK

This User Gave Thanks to Chubler_XL For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies

2. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

3. Shell Programming and Scripting

Day of the week or Month in a foreign language

Hey guys, i'm a very new shell script user. I've been looking everywhere for a proper script to display the day of the week or the month, accurately, in a foreign language of my choosing. Something where i can just type in the appropriate word in a foreign language in the script and get the... (2 Replies)
Discussion started by: ibizagreg
2 Replies

4. UNIX for Dummies Questions & Answers

Get Quarter Date

Hi I need to produce a report that the start date must be the first day of the current quarter. Therefore a repor that is run today the start date would be 01/10/2010 (ddmmyyyy). Obvioulsy I could hard code this date in but what happens when the report is run in January the start of the... (6 Replies)
Discussion started by: theref
6 Replies

5. Shell Programming and Scripting

Generate quarter dates with begin date and end date

Hi All, I am trying to generate quarter dates with user giving input as begin date and end date. Example: Input by user: begin_date = "2009-01-01" end_date = 2010-04-30" required output: 2009-01-01 2009-03-31 09Q01 2009-04-01 2009-06-30 09Q02 . . till 2010-01-01 2010-03-31 10Q01 ... (9 Replies)
Discussion started by: sol_nov
9 Replies

6. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

7. UNIX for Advanced & Expert Users

How can i calculate a Quarter of a Month

I im just a beginner here. I wanted to know how to calculate the Quarter of a Month, and i want to assign Number like if the month falls on 1st quarter then i have to assign to 1 then going on till the last Quarter!! Any help will be much use to me.. ~Renne (2 Replies)
Discussion started by: pidu_rak
2 Replies

8. Shell Programming and Scripting

Execute a script on 4 week of the month

I need help to write a script and it will execute on Saturday of the last week of every month. For example : 09/30/2006 is the last Saturday on Sept. 2006 08/26/2006 is the last Saturday on Aug. 2006 07/29/2006 is the last Saturday on July. 2006 etc.. ... (1 Reply)
Discussion started by: tbdo88
1 Replies

9. Shell Programming and Scripting

Getting week in month.???

Hi All, I have a tricky problem. I need to write a shell script (bash) which identifies which week off the month it is. I need to create a partition each week. So for the first week (where first of the week is Monday) of March i want to create partition_march_01 and for the second partition... (1 Reply)
Discussion started by: Zak
1 Replies
Login or Register to Ask a Question