Sponsored Content
Full Discussion: Last friday of every month
Top Forums Shell Programming and Scripting Last friday of every month Post 302211804 by vbe on Friday 4th of July 2008 12:27:14 PM
Old 07-04-2008
Using what you can find in this forum:
https://www.unix.com/shell-programmin...h-month-2.html

(My box is an HP hpux11.11)
ant:/home/vbe/wks $ cal_use
ENTER Month Year format mm yyyy 06 2008
CALDATE : 06 2008
Last Friday is 27
ant:/home/vbe/wks $ cal_use
ENTER Month Year format mm yyyy 07 2008
CALDATE : 07 2008
Last Friday is 25
ant:/home/vbe/wks $ cal_use
ENTER Month Year format mm yyyy 02 2008
CALDATE : 02 2008
Last Friday is 29
ant:/home/vbe/wks $


ant:/home/vbe/wks $ more cal_use
#!/usr/bin/ksh

echo " ENTER Month Year format mm yyyy \c "
read CALDATE
echo " CALDATE : " $CALDATE

FRI=$(cal $CALDATE | tail +3 | cut -c16,17 | sed '/^ *$/d' | sed -n '5p')
# or FRI=$(cal $CALDATE | tail +3 | cut -c21,22 | sed '/^ *$/d' | sed -n '5p') under AIX...
if [ "$FRI" -eq "" ]
then
FRI=$(cal $CALDATE | tail +3 | cut -c16,17 | sed '/^ *$/d' | sed -n '4p')
#FRI=$(cal $CALDATE | tail +3 | cut -c21,22 | sed '/^ *$/d' | sed -n '4p') for AIX...
fi
echo "Last Friday is " $FRI

#cal_use: END

All the best

Last edited by vbe; 07-05-2008 at 07:59 AM.. Reason: add empty line for reading convenience
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help, Every friday in a month

I am trying to write a script that shows every Friday in a month. I used cal $1 $2 | grep -v "^$" | awk '{print $6}' It doesn't work for the frist week of Friday because calendar command output has some spaces in the first line and awk '{print $6}' doesn't work. Anybody help me with this... (3 Replies)
Discussion started by: LAY
3 Replies

2. Shell Programming and Scripting

how can i find the third friday of each month?

Help please! I need to read the calendar and put the date of the third Friday of each month into a variable for comparison in an "if" statement. How would I do this? Thnx, leslie02 (10 Replies)
Discussion started by: leslie02
10 Replies

3. 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

4. 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

5. Shell Programming and Scripting

cron job to run on second to last friday each month

I needed a cron job to run on the second to last friday of every month. Our servers are running HP-UX, and the HP-UX date command is pretty basic and does not have all of the fancy options that Linux date command does, and it does not have the ability at all to return future dates. So I had to... (0 Replies)
Discussion started by: lupin..the..3rd
0 Replies

6. UNIX for Dummies Questions & Answers

[Solved] Cron - job to run every 3rd Friday of the month only

Hi Expert Please help me to set a cron job schedule, Ihave a job that run every 3rd Friday of the month at 1030am. I tried to set up like this, but the job still runs every friday at 1030am. I want the job to run every 3rd Friday of the month at 1030am only 30 10 15,16,17,18,19,20,21... (2 Replies)
Discussion started by: kaibiganmi
2 Replies

7. Red Hat

How to find/display out last Friday's date of the month?

Hello, Can you please help me find/display out last Friday's date of the month using command in Unix/Linux (3 Replies)
Discussion started by: sunnysthakur
3 Replies

8. Shell Programming and Scripting

How to add decimal month to some month in sql, php, perl, bash, sh?

Hello, i`m looking for some way to add to some date an partial number of months, for example to 2015y 02m 27d + 2,54m i need to write this script in php or bash or sh or mysql or perl in normal time o unix time i`m asking or there are any simple way to add partial number of month to some... (14 Replies)
Discussion started by: bacarrdy
14 Replies

9. Shell Programming and Scripting

Need last month files after 10th of every month

Hi, I need all file names in a folder which has date >= 10th of last month, Example : files in folder AUTO_F1_20140610.TXT BUTO_F1_20140616.TXT CUTO_F1_20140603.TXT FA_AUTO_06012014.TXT LA_AUTO_06112014.TXT MA_AUTO_06212014.TXT ZA_AUTO_06232014.TXT Output: AUTO_F1_20140610.TXT... (9 Replies)
Discussion started by: nani1984
9 Replies

10. Linux

Bash Display First Friday of the next month

Hello, I need to find the date of next first Friday of the month and set as a variable in a bash script ie - FIRSTFRIDAY=$(date -dfirst-friday +%d) I know date -dfirst-friday doesn't work, but unsure if I can use this / cal + awk or something else to find the right date of the... (7 Replies)
Discussion started by: summerdays
7 Replies
CALENDAR(1)						    BSD General Commands Manual 					       CALENDAR(1)

NAME
calendar -- reminder service SYNOPSIS
calendar [-a] [-A num] [-B num] [-F friday] [-f calendarfile] [-t dd[.mm[.year]]] [-W num] DESCRIPTION
The calendar utility checks the current directory for a file named calendar and displays lines that begin with either today's date or tomor- row's. On the day before a weekend (normally Friday), events for the next three days are displayed. The following options are available: -A num Print lines from today and the next num days (forward, future). -a Process the ``calendar'' files of all users and mail the results to them. This requires super-user privileges. -B num Print lines from today and the previous num days (backward, past). -F friday Specify which day of the week is ``Friday'' (the day before the weekend begins). Default is 5. -f calendarfile Use calendarfile as the default calendar file. -t dd[.mm[.year]] For test purposes only: set date directly to argument values. -W num Print lines from today and the next num days (forward, future). Ignore weekends when calculating the number of days. To handle calendars in your national code table you can specify ``LANG=<locale_name>'' in the calendar file as early as possible. To handle national Easter names in the calendars ``Easter=<national_name>'' (for Catholic Easter) or ``Paskha=<national_name>'' (for Orthodox Easter) can be used. Other lines should begin with a month and day. They may be entered in almost any format, either numeric or as character strings. If the proper locale is set, national month and weekday names can be used. A single asterisk (``*'') matches every month. A day without a month matches that day of every week. A month without a day matches the first of that month. Two numbers default to the month followed by the day. Lines with leading tabs default to the last entered date, allowing multiple line specifications for a single date. ``Easter'', is Easter for this year, and may be followed by a positive or negative integer. ``Paskha'', is Orthodox Easter for this year, and may be followed by a positive or negative integer. Weekdays may be followed by ``-4'' ... ``+5'' (aliases for last, first, second, third, fourth) for moving events like ``the last Monday in April''. By convention, dates followed by an asterisk are not fixed, i.e., change from year to year. Day descriptions start after the first <tab> character in the line; if the line does not contain a <tab> character, it is not displayed. If the first character in the line is a <tab> character, it is treated as a continuation of the previous line. The ``calendar'' file is preprocessed by cpp(1), allowing the inclusion of shared files such as lists of company holidays or meetings. If the shared file is not referenced by a full pathname, cpp(1) searches in the current (or home) directory first, and then in the directory /usr/share/calendar. Empty lines and lines protected by the C commenting syntax (/* ... */) are ignored. Some possible calendar entries (<tab> characters highlighted by sequence) LANG=C Easter=Ostern #include <calendar.usholiday> #include <calendar.birthday> 6/15 June 15 (if ambiguous, will default to month/day). Jun. 15 June 15. 15 June June 15. Thursday Every Thursday. June Every June 1st. 15 * 15th of every month. May Sun+2 second Sunday in May (Muttertag) 04/SunLast last Sunday in April, summer time in Europe Easter Easter Ostern-2 Good Friday (2 days before Easter) Paskha Orthodox Easter FILES
calendar file in current directory ~/.calendar calendar HOME directory. A chdir is done into this directory if it exists. ~/.calendar/calendar calendar file to use if no calendar file exists in the current directory. ~/.calendar/nomail do not send mail if this file exists. The following default calendar files are provided: calendar.all File which includes all the default files. calendar.australia Calendar of events in Australia. calendar.birthday Births and deaths of famous (and not-so-famous) people. calendar.christian Christian holidays. This calendar should be updated yearly by the local system administrator so that roving holidays are set correctly for the current year. calendar.computer Days of special significance to computer people. calendar.croatian Calendar of events in Croatia. calendar.freebsd Birthdays of FreeBSD committers. calendar.french Calendar of events in France. calendar.german Calendar of events in Germany. calendar.history Everything else, mostly U.S. historical events. calendar.holiday Other holidays, including the not-well-known, obscure, and really obscure. calendar.judaic Jewish holidays. This calendar should be updated yearly by the local system administrator so that roving holidays are set correctly for the current year. calendar.music Musical events, births, and deaths. Strongly oriented toward rock 'n' roll. calendar.newzealand Calendar of events in New Zealand. calendar.russian Russian calendar. calendar.southafrica Calendar of events in South Africa. calendar.usholiday U.S. holidays. This calendar should be updated yearly by the local system administrator so that roving holidays are set correctly for the current year. calendar.world Includes all calendar files except for national files. COMPATIBILITY
The calendar program previously selected lines which had the correct date anywhere in the line. This is no longer true, the date is only recognized when it occurs at the beginning of a line. SEE ALSO
at(1), cpp(1), mail(1), cron(8) HISTORY
A calendar command appeared in Version 7 AT&T UNIX. BUGS
The calendar utility does not handle Jewish holidays and moon phases. BSD
June 13, 2002 BSD
All times are GMT -4. The time now is 10:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy