fetching Month end using cal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting fetching Month end using cal
# 1  
Old 03-04-2009
fetching Month end using cal

Hi ,

Can someone please assist to get monthend using cal utility and monthend shouldn't be saturday or sunday.

Cheers,
gehlnar
# 2  
Old 03-04-2009
shell script

Code:
#!/bin/ksh

monthend()
{
    if [[  -z "$1" ]] ; then
	    set -A arr $(cal | tail -3 | tr -s '\n'  ' ')
	else
	    set -A arr $(cal $1 $2| tail -3 | tr -s '\n'  ' ')
	fi    
	p=$((  ${#arr[*]} % 7  ))
	element=0
	case "$p" in 
		'0') element=$(( ${#arr[*]} - 2 ));;
		'1') element=$(( ${#arr[*]} - 3 ));;
		'2') element=$(( ${#arr[*]} - 1 ));;
		'3') element=$(( ${#arr[*]} - 1 ));;
		'4') element=$(( ${#arr[*]} - 1 ));;
		'5') element=$(( ${#arr[*]} - 1 ));;
		'6') element=$(( ${#arr[*]} - 1 ));;
    esac                            
    echo ${arr[element]}

}
# example current month monthend:
cal       # show the calendar
monthend  # print monthend 

# for all of 2008 

for i in 1 2 3 4 5 6 7 8 9 10 11 12
do
   cal $i 2008
   monthend $i 2008
done

#usage:
monthend | read thismonthend

# 3  
Old 03-06-2009
Hi Jim,

Thanks for your assitance.

Cheers,
gehlnar
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Get the next month end date

how to get the next month end date. dt=01312014 output=02282014 (2 Replies)
Discussion started by: w020637
2 Replies

2. Shell Programming and Scripting

Cron for end of month

Hello, I'm on FreeBSD 8.2-STABLE shell and I was trying the following cron entry for end of month: 59 23 * * * && /home/user/eomt.sh >/dev/null 2>&1 I get the following error Subject: Cron <user@shell> eomt.sh contains the following codes #!/bin/sh rm /home/user/tst/logs/* &&... (9 Replies)
Discussion started by: user`
9 Replies

3. Shell Programming and Scripting

Fetching a set of lines with start and end

Hi Folks, Need help in fetching a group of lines with a start and end strings. Example is shown below. start#morning tea jog breakfast end start#afternoon lunch work chat end start#evening snacks tea chat (6 Replies)
Discussion started by: jayadanabalan
6 Replies

4. Shell Programming and Scripting

Displaying time left to end of day, week, month?

Hello, basically I'm looking after a way of showing how many time is left to the end the day, week, month... I can't seem to figure this out, so could one of you skilled guys tell me how should this be approached? Examples: Time left: Day: 12h 12m 11s Week: 4d 12h 12m 11s Month:... (4 Replies)
Discussion started by: TehOne
4 Replies

5. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 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. Shell Programming and Scripting

End of Month - Cron Jobs

I am running AIX 5.3 with the default shell as ksh. I would like to know how to run a cron job on this system the last calendar day of the month. I found an example, but, I'm not sure if it will work with AIX and ksh... 02 16 * * * && /home/user/job-eom.kshI also need to be able to run a... (2 Replies)
Discussion started by: jthompson333
2 Replies

8. UNIX for Advanced & Expert Users

last month end date

Hi, How to get the lastmonth's end date? (have current date) through s shell script. I need to get it and pass it to a procedure. Please advice. Thanks in advance. (7 Replies)
Discussion started by: vanathi
7 Replies

9. UNIX for Dummies Questions & Answers

setting up cron job for month end week report

Hi all, Needs your help in scheduling a cron job for the below mentioned requirement. Just let me know if anybody has a similar job running as mentioned below: Month end reports - Report of all items created in a parent table that were created during the week. Presently this report runs... (3 Replies)
Discussion started by: Bhups
3 Replies

10. UNIX for Advanced & Expert Users

Unix Cron Month End Processing

Is it possible to use cron to schedule a job that will run the first 3 Sunday's during a month in addition to the last day of the month? (3 Replies)
Discussion started by: cpete
3 Replies
Login or Register to Ask a Question