![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Pleasae Help!!!
Hi List,
Hello List, I do not have any experiece with the shell scripting. I need the help to solve an issue. This script is calculating the value of Nth day correctly which is just for next one month. Now what I need to do is to calculate the same occurence pattern for next 12 months. I will really really appreciate if someone can help me what to adjust in the code which will bring the value of Nth day for whole next 12 months. #! /bin/ksh # NthWeekday.sh - returns the date (day only) of the Nth Weekday of the month # Such as First Monday, Second Wednesday, etc # Usage: NthWeekday.sh Month Year Weekday Nth # Month - The month to search, numeric format (ie 1, 2, 3, etc) # Year - The year to search, four digits (ie 2008, 2009, etc) # Weekday - The day of the week to search for (ie Sunday, Monday, etc) # Nth - The ordinal value to search for (ie First, Second, Third, Fourth) LOGFILE=/logs/NthWeekday.log MONTH=$1 YEAR=$2 WEEKDAY=$3 NTH=$4 echo $$,`date`",Running NthWeekday.sh $MONTH $YEAR $WEEKDAY $NTH" >> $LOGFILE # Convert WEEKDAY to numeric format if [ "$WEEKDAY" = "Sunday" ]; then WEEKDAY=0 fi if [ "$WEEKDAY" = "Monday" ]; then WEEKDAY=1 fi if [ "$WEEKDAY" = "Tuesday" ]; then WEEKDAY=2 fi if [ "$WEEKDAY" = "Wednesday" ]; then WEEKDAY=3 fi if [ "$WEEKDAY" = "Thursday" ]; then WEEKDAY=4 fi if [ "$WEEKDAY" = "Friday" ]; then WEEKDAY=5 fi if [ "$WEEKDAY" = "Saturday" ]; then WEEKDAY=6 fi # Convert NTH to numeric format if [ "$NTH" = "First" ]; then NTH=1 fi if [ "$NTH" = "Second" ]; then NTH=2 fi if [ "$NTH" = "Third" ]; then NTH=3 fi if [ "$NTH" = "Fourth" ]; then NTH=4 fi # Find the date for the first WEEKDAY in MONTH FIRSTSATURDAY=`cal $MONTH $YEAR | sed -n '3s/. //gp'` FIRSTWEEKDAY=`expr $FIRSTSATURDAY + 7 + $WEEKDAY` FIRSTWEEKDAY=`expr $FIRSTWEEKDAY % 7 + 1` # Find the date for the Nth WEEKDAY in MONTH TEMP=`expr $NTH - 1` NTHWEEKDAY=`expr $FIRSTWEEKDAY + 7 \* $TEMP` echo $NTHWEEKDAY echo $$,`date`",NthWeekday.sh returned $NTHWEEKDAY" >> $LOGFILE #exit Thanks in advace, |
![]() |
| Bookmarks |
| Tags |
| date |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|