Sponsored Content
Top Forums Shell Programming and Scripting crontab entry to run every last day of the month Post 302234437 by jsandova on Tuesday 9th of September 2008 04:41:58 PM
Old 09-09-2008
I had a similar dilemma where I need to run a backup script every 2nd Tuesday of the Month. So I added the following to my script:

Code:
TODAY=`/bin/date +%d | cut -d"0" -f2`
TUE=`cal | awk {'print $3'} | xargs | /usr/bin/cut -d" "  -f3`
#See if today matches the 2nd Tuesday of the month
if [ "$TODAY" -ne "$TUE" ] ; then

        exit 0

else


Moderator's Comments:
Mod Comment code tags please, thanks.

Last edited by zaxxon; 10-20-2011 at 04:55 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron to run first day of month to calculate date 3 months ago

Hi, I would like to find out how can i calculate a date which is 3 months ago. I intend to run a cron job on the 1st of every month, and calculate the month 4 months earlier from the date. For example, if today's date is 1st May 2007, i would like to return 012007( January 2007). i can get... (1 Reply)
Discussion started by: new2ss
1 Replies

2. UNIX for Dummies Questions & Answers

cron script -run every 2nd day of month except Monday

I know I can't schedule this in cron and would have to write a wrapper around my script and schedule it in cron ....but not sure how do to this? How do I exclude Monday if the 2nd day of the month falls on a Monday? Thanks. I tried this: 0 0 2 * 0,2-6 command And I know this doesnt... (2 Replies)
Discussion started by: newtou
2 Replies

3. Solaris

crontab entry to run a script on 1st of every month.

What should be the crontab entry in solaris to run a script on 1st of every month? Is this correct? 00 02 1 * * <script to be executed> (5 Replies)
Discussion started by: deepaksahni0109
5 Replies

4. Shell Programming and Scripting

Crontab to skip only one entry in a day???

Hello Friends, I have a cron tab like this: 10,40 1-23 * * * /script i want to skip only one execution at 00:10, so basically i want it to execute every hour at 10th and 40th minute, except 00:10. Could anyone help me doing this Thanks folks :b: (4 Replies)
Discussion started by: Prateek007
4 Replies

5. Shell Programming and Scripting

run the script for last day of the month

Hello Experts, I have a script which i want to run the on last day of every month. let say I have backup.sh script which i want to run it every month last day. Can anyone please help :confused: thanks (4 Replies)
Discussion started by: aks_1902
4 Replies

6. UNIX for Dummies Questions & Answers

Running Script via Crontab on 2nd Working day each month

Hello Guys, I have a questions regarding running a shell script every second working day each month. I have no clue how solve this problem :wall:. Important is that it has to be the second working (Mo-Fr). Example: If 1st and 2nd Days of month are Sat and Sun the script must run on 4th day... (5 Replies)
Discussion started by: Hollo
5 Replies

7. Shell Programming and Scripting

Writing a script to run weekly/monthly - check for weekday or day-of-the-month

Hi all, I currently have a UNIX file maintenance script that runs daily as a cron job. Now I want to change the script and create functions/sub inside it that runs on a weekly or monthly basis. To run all the scripts' daily maintenance, I want to schedule it in cron as simply maint.sh... (1 Reply)
Discussion started by: newbie_01
1 Replies

8. Shell Programming and Scripting

Simpler crontab entry to execute pgm on last day of the month

The following bash command line works for the last day of the month. Test by replacing the 1 with tomorrows day of month number && echo "Day before tomorrow"Can it be used within crontab? As * * 28-31 * * && echo "Today ls last day of month" >>/tmp/crontabtestI tried to test crontab with... (1 Reply)
Discussion started by: lsatenstein
1 Replies

9. Shell Programming and Scripting

Script to run on 2 4 and 7 day of the month

I am looking for a unix script which could run a job on 2, 4 and 7 working day of the month. if the days are falling on the saturday/sunday. it should run on the next day. Thank you.. (9 Replies)
Discussion started by: tradingspecial
9 Replies

10. UNIX for Beginners Questions & Answers

Dynamic crontab entry for day and night

I have query apply crontab entry that the script executes as below day hours (before 8:00 PM and after 7:00 AM) execute every 5 min in Night hours (after 8:00 PM to 7:00 AM) executes every 15 min How can we set such entry in crontab ? (4 Replies)
Discussion started by: kaushik02018
4 Replies
CAL(1)                                                      BSD General Commands Manual                                                     CAL(1)

NAME
cal, ncal -- displays a calendar and the date of Easter SYNOPSIS
cal [-31jy] [-A number] [-B number] [-d yyyy-mm] [[month] year] cal [-31j] [-A number] [-B number] [-d yyyy-mm] -m month [year] ncal [-C] [-31jy] [-A number] [-B number] [-d yyyy-mm] [[month] year] ncal [-C] [-31j] [-A number] [-B number] [-d yyyy-mm] -m month [year] ncal [-31bhjJpwySM] [-A number] [-B number] [-H yyyy-mm-dd] [-d yyyy-mm] [-s country_code] [[month] year] ncal [-31bhJeoSM] [-A number] [-B number] [-d yyyy-mm] [year] DESCRIPTION
The cal utility displays a simple calendar in traditional format and ncal offers an alternative layout, more options and the date of Easter. The new format is a little cramped but it makes a year fit on a 25x80 terminal. If arguments are not specified, the current month is dis- played. The options are as follows: -h Turns off highlighting of today. -J Display Julian Calendar, if combined with the -o option, display date of Orthodox Easter according to the Julian Calendar. -e Display date of Easter (for western churches). -j Display Julian days (days one-based, numbered from January 1). -m month Display the specified month. If month is specified as a decimal number, appending 'f' or 'p' displays the same month of the follow- ing or previous year respectively. -o Display date of Orthodox Easter (Greek and Russian Orthodox Churches). -p Print the country codes and switching days from Julian to Gregorian Calendar as they are assumed by ncal. The country code as deter- mined from the local environment is marked with an asterisk. -s country_code Assume the switch from Julian to Gregorian Calendar at the date associated with the country_code. If not specified, ncal tries to guess the switch date from the local environment or falls back to September 2, 1752. This was when Great Britain and her colonies switched to the Gregorian Calendar. -w Print the number of the week below each week column. -y Display a calendar for the specified year. This option is implied when a year but no month are specified on the command line. -3 Display the previous, current and next month surrounding today. -1 Display only the current month. This is the default. -A number Months to add after. The specified number of months is added to the end of the display. This is in addition to any date range selected by the -y, -3, or -1 options. For example, ``cal -y -B2 -A2'' shows everything from November of the previous year to Febru- ary of the following year. Negative numbers are allowed, in which case the specified number of months is subtracted. For example, ``cal -y -B-6'' shows July to December. And ``cal -A11'' simply shows the next 12 months. -B number Months to add before. The specified number of months is added to the beginning of the display. See -A for examples. -C Completely switch to cal mode. For cal like output only, use -b instead. -N Switch to ncal mode. -d yyyy-mm Use yyyy-mm as the current date (for debugging of date selection). -H yyyy-mm-dd Use yyyy-mm-dd as the current date (for debugging of highlighting). -M Weeks start on Monday. -S Weeks start on Sunday. -b Use oldstyle format for ncal output. A single parameter specifies the year (1-9999) to be displayed; note the year must be fully specified: ``cal 89'' will not display a calendar for 1989. Two parameters denote the month and year; the month is either a number between 1 and 12, or a full or abbreviated name as speci- fied by the current locale. Month and year default to those of the current system clock and time zone (so ``cal -m 8'' will display a calen- dar for the month of August in the current year). Not all options can be used together. For example, the options -y, -3, and -1 are mutually exclusive. If inconsistent options are given, the later ones take precedence over the earlier ones. A year starts on January 1. Highlighting of dates is disabled if stdout is not a tty. SEE ALSO
calendar(3), strftime(3) HISTORY
A cal command appeared in Version 5 AT&T UNIX. The ncal command appeared in FreeBSD 2.2.6. The output of the cal command is supposed to be bit for bit compatible to the original Unix cal command, because its output is processed by other programs like CGI scripts, that should not be broken. Therefore it will always output 8 lines, even if only 7 contain data. This extra blank line also appears with the original cal command, at least on Solaris 8 AUTHORS
The ncal command and manual were written by Wolfgang Helbig <helbig@FreeBSD.org>. BUGS
The assignment of Julian-Gregorian switching dates to country codes is historically naive for many countries. Not all options are compatible and using them in different orders will give varying results. BSD March 14, 2009 BSD
All times are GMT -4. The time now is 09:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy