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
pal(1)							      General Commands Manual							    pal(1)

NAME
pal - calendar with events SYNOPSIS
pal [options] DESCRIPTION
pal is a command-line calendar utility. It displays a cal(1)-like calendar and events specified in text files. OPTIONS
The following options are provided by pal: -d date Show events on the given date. Valid formats for date include: dd, mmdd, yyyymmdd, 'yesterday', 'today', 'tomorrow', 'n days away', 'n days ago', first two letters of weekday, 'next ' followed by first two letters of weekday, 'last ' followed by first two letters of weekday, '1 Jan 2000', 'Jan 1 2000'. -r n Display events occurring in the next n days (counting today). By default, n is 0 and no events are displayed. For example, using -r 1 makes pal display events occurring today. If -d is used too, the range is relative to date instead of the current date. -r p-n Display a list of events occurring in the past p days (not counting today) and the next n days (counting today). For example -r 1-1 will show yesterday's and today's events. If -d is used too, the range is relative to date instead of the current date. -s regex Search for any occurrences of an event matching the regular expression (regex) occurring in the range of dates specified with -r. This command searches both the event description and the type of event (specified at the top of a calendar file). This search is case insensitive. -x n Expunge events that are n or more days old if they do not occur again in the future. pal will not expunge events from the calendars loaded from /usr/share/pal; even if you are root and you have added events to the calendars that are not recurring. When -x is used with -v, the events that are expunged will be displayed. -c n Display a calendar with n lines (default: 5). -f file Load file instead of ~/.pal/pal.conf. -u username Load /home/username/.pal/pal.conf instead of ~/.pal/pal.conf. -p palfile Override the .pal files loaded from pal.conf. This will only load palfile. For convenience, if palfile is a relative path, pal looks for the file relative from ~/.pal/, if not found, it tries relative to /usr/share/pal/, if not found it tries relative to your current directory. (This behavior might change in the future.) Using an absolute path will work as you expect it to. -m Manage events interactively. Events can be added, modified and deleted with this interface. --color Force use of colors, regardless of terminal type. --nocolor Do not use colors, regardless of terminal type. --mail Generates output readable by sendmail by adding "From:" and "Subject:" fields and forcing --nocolor. For example, you could mail yourself a reminder of the upcoming events in the next week with pal --mail -r 7 | sendmail username. Note: For the calendar to appear correctly, make sure your email client is using a fixed width font. --html Generates a HTML calendar suitable for display on a web page. It does not generate a complete HTML document so that you can add your website's header and footer around the calendar. The number of months shown on the calendar can be adjusted with -c. You will need to use Cascading Style Sheets (CSS) to change how the calendar appears; if you do not use a style sheet, the calendar will not have any borders. See /usr/share/doc/pal/examples/example.css for an example style. SECURITY NOTE: If you set up pal so it is being executed server-side, it is recommended that you do not allow web page visitors to directly change the parameters sent to pal. Allowing users to pass strange parameters (such as extremely long ones) can be a security risk. --latex Generates a LaTeX source for a calendar that can be used to generate a printer-friendly DVI (run "pal --latex > file.tex; latex file.tex"), PostScript or PDF (run "pal --latex > file.tex; pdflatex file.tex"). The number of months shown on the calendar can be adjusted with -c. -v Verbose output. --version Display version information. -h, --help Display a help message. EVENT DESCRIPTIONS
Years since year YYYY pal will replace !YYYY! (where YYYY is a year) with the current year minus YYYY. This feature is particularly useful for birthdays. For example, the event text for a birthday could be: John Doe was born on this day in 1990. He is !1990! years old. Sort by time If events have a time in the event description, pal will sort these events by time. The time in the event description must be of the format h:mm or hh:mm (where hh is 0-23). If an event has more than one time in the event description, pal will sort the event by the first time. Events that do not have times in them are shown before all the events that do have times. Events without times are sorted in the order that they are loaded in pal.conf. FILE FORMATS
Unless -f or -u is used, pal looks for (or tries to create if it doesn't exist) a configuration file named ~/.pal/pal.conf. pal.conf con- tains settings for pal and a list other files that contain events to be displayed on the calendar. The file formats for pal.conf and the event files are described below. pal.conf file filename [ (color) ] Loads an event file named filename. If filename isn't found in ~/.pal, pal will look for it in /usr/share/pal. The color param- eter is optional, it will display the events in the file with the given color. Valid colors: black, red, green, yellow, blue, magenta, cyan, white file_hide filename [ (color) ] Loads an event file name filename. These events are not indicated in the calendar that is printed, but they are displayed when the -r argument is used. If filename isn't found in ~/.pal, pal will look for it in /usr/share/pal. The color parameter is optional, it will display the events in the file with the given color. Valid colors: black, red, green, yellow, blue, magenta, cyan, white event_color color The default color used for events. Valid colors: black, red, green, yellow, blue, magenta, cyan, white week_start_monday If this keyword is defined, the calendar weeks start on Monday instead of Sunday. date_fmt string Changes how dates are displayed when the -r -d or -s arguments are used. string can be a date format string that follows the format used by strftime(3). Type man strftime for more information. string is set to %a %e %b %Y by default (example: Sun 8 Aug 2010). reverse_order Display all event listings in descending order. hide_event_type Hide the event type (shown in before a ':') when listing events. The event type is defined at the top of the file that the event is found in. cal_on_bottom Display calendar at the end of the output. no_columns Display calendar in one column instead of two. compact_list List events that are shown when using -r in a more compact form. compact_date_fmt Format for the date displayed when compact_list is used. See date_fmt for more information. default_range range If you get tired of always using -r, you can set the default value for -r here. See the information on -r above to see possible values for range. Note: Remember that this will affect what is displayed when -d and -s are used too. Event Files Event files are ASCII or UTF-8 text files (usually with a .pal ending) that define events for pal to show. Example event files can be found in /usr/share/pal. The first line in these files indicate settings that apply to all of the events in the file. The first line starts with two characters that should be used in the calendar that pal displays. A longer description of the kinds of events in the file follows the two characters. This description will be displayed when the -r argument is used. All other lines in the file are in the format date event. date defines when the event occurs and event is a string that describes the event. Below is a description of the different strings that can be used with date: Events that occur only once Use the format yyyymmdd. Daily events The format DAILY can be used for an event that happens every day. Weekly events The format MON, TUE, WED, THU, FRI, SAT and SUN can be used for an event that happens every week. Monthly events Use the format 000000dd. Annual events Use the format 0000mmdd. Annual: Events that occur on the Nth day of a month. Use the format *mmnd. Where d is the day (1 = Sunday, 7 = Saturday). Example: *1023 (10=Oct; 2="second"; 3=Tuesday ==> Second Tuesday in October, every year). Monthly: Events that occur on the Nth day of a month. Use the format *00nd. Where d is the day (1 = Sunday, 7 = Saturday). Example: *0023 (2="second"; 3=Tuesday ==> Second Tuesday of every month). Annual: Events that occur on a certain last day of a month Use the format *mmLd. Example: *10L3 (10=Oct; L=Last; 3=Tuesday ==> Last Tuesday in October). This is useful for some holidays. Monthly: Events that occur on a certain last day of a month Use the format *00Ld. Example: *00L3 (3=Tuesday ==> Last Tuesday of every month). Todo events The format TODO can be used for an event that always happens on the day that you run pal. This enables you to use pal to keep track of items in your todo list(s). Easter related events Use the format Easter for Easter Sunday. Use the format Easter+nnn for events that occur nnn days after Easter. Use the format Easter-nnn for events that occur nnn days before easter. Recurring events with start and end dates If a recurring event has a starting date and an ending date, you can use the date format DATE:START:END where DATE is a recurring date format above. START and END are dates in the yyyymmdd format that specify the starting and ending date of the recurring event. START and END dates are inclusive. For example, if an event happens every Wednesday in October 2010, you could use this format: WED:20101001:20101031 Bi-weekly, Bi-annual, etc. events If a recurring event does only occurs every Nth occurence, you can add a /N to the event of the date string for that event. A start date must be specified. For example, a bi-monthly event that occurs on the first of the month can be specified as 00000001/2:20000101. INTERNATIONALIZATION AND LOCALIZATION
The calendar files that pal uses must be ASCII encoded or UTF-8 encoded text files (ASCII is a subset of UTF-8). UTF-8 enables the calen- dar files to work on any system regardless of the default encoding scheme. When pal prints text, it converts the UTF-8 characters into the local encoding for your system. If pal does not display international characters and you are using a UTF-8 calendar file, check to make sure that your locale is set correctly. You can see your locale settings by running "locale". You can see the character set that pal is using for output by running pal with "-v". If pal does not have a translation for your language and you are interested in creating a translation, see the po/README file that is distributed with the source code for pal. FILES
~/.pal/pal.conf: Contains configuration information for pal and a list of .pal text files that contain events. /etc/pal.conf: This pal.conf file is copied to ~/.pal/pal.conf when a user runs pal for the first time. /usr/share/pal: Contains several calendar files for pal. BUGS
Bugs may be reported via http://palcal.sourceforge.net/. SEE ALSO
strftime(3), cal(1), regex(7) SIMILAR PROGRAMS
pal is similar to BSD's calendar program and GNU's more complex gcal program. AUTHORS
Scott Kuhl pal(1)
All times are GMT -4. The time now is 12:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy