Solved

unix k shell script on dates

Posted on 2009-03-31
8
363 Views
Last Modified: 2013-12-26
I need a script in ksh that when I provide a month and year as input let us say JAN-2009 then it should split the dates into weeks and I need to store them as

WEEK1_START = '2009-01-01-00.00.00'
WEEK1_END = '2009-01-09-00.00.00'
WEEK2_START =  '2009-01-09-00.00.00'
WEEK2_END = '2009-01-16-00.00.00'
WEEK3_START ='2009-01-16-00.00.00'
WEEK3_END = '2009-01-23-00.00.00'
WEEK4_START = '2009-01-23-00.00.00'
WEEK4_END =  '2009-02-01-00.00.00'

Let me know how to get this.. I wanted weekly dates in this format since I wanted to use the above values in my db2 script which has datetime as datatype.. Thanks!!
0
Comment
Question by:mahjag
  • 4
  • 4
8 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 24033703
how do you decide when a week starts and ends?
it looks like your weeks are 8, 9, or 10 days long, and usually start and end on a Friday.
Can you explain the rules for how that works?
0
 

Author Comment

by:mahjag
ID: 24033795
We got this from a customer response and would like to stick with the same dates for any month, let me know if that will be an issue..
0
 
LVL 84

Expert Comment

by:ozo
ID: 24033871
So, always 1st to 9th, 9th to 16th, 16th to 23rd, and 23rd to 1st?
0
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
ID: 24034127
#!/bin/ksh
JAN=01
FEB=02
MAR=03
APR=04
MAY=05
JUN=06
JUL=07
AUG=08
SEP=09
OCT=10
NOV=11
DEC=12
typeset -n mon=${1%-*}
year=${1#*-}
WEEK1_START=$year-${mon}-01-00.00.00
WEEK1_END=$year-${mon}-09-00.00.00
WEEK2_START=$year-${mon}-09-00.00.00
WEEK2_END=$year-${mon}-16-00.00.00
WEEK3_START=$year-${mon}-16-00.00.00
WEEK3_END=$year-${mon}-16-00.00.00
WEEK4_START=$year-${mon}-23-00.00.00
typeset -Z2 e=$(( $mon % 12 + 1 ))
WEEK4_END=$year-${e}-01-00.00.00
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:mahjag
ID: 24040419
Hi Ozo

I just ran the script above and got error
./weekly_dates.ksh[14]: typeset: bad option(s)
do you know why?
0
 

Author Comment

by:mahjag
ID: 24040516
I looked at man typeset and did not see option for -n
I changed that value to -x and still got syntax errors. Hope I get a solution that is tested, here is the syntax error..
./weekly_dates.ksh[23]:   % 12 + 1 : syntax error - any clues?
0
 

Author Comment

by:mahjag
ID: 24040584
I know this question is closed - but would like to get some response here to complete the task.
0
 
LVL 84

Expert Comment

by:ozo
ID: 24046784
what version of ksh are you running?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now