The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
fetching paragraphs with SED ipat Shell Programming and Scripting 4 02-02-2009 11:38 AM
Fetching unique values from file shivi707 UNIX Desktop for Dummies Questions & Answers 1 01-09-2009 08:33 AM
Problems fetching EMC disks to Solaris OS. orac SUN Solaris 10 08-18-2008 07:58 AM
IMU sample fetching over RS485 aloha_boi High Level Programming 0 07-23-2008 04:05 AM
fetching a web page in C rayne High Level Programming 4 08-08-2007 10:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-04-2009
gehlnar gehlnar is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
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 (permalink)  
Old 03-04-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,802
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 (permalink)  
Old 03-06-2009
gehlnar gehlnar is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
Hi Jim,

Thanks for your assitance.

Cheers,
gehlnar
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0