Sponsored Content
Top Forums Shell Programming and Scripting crontab entry to run every last day of the month Post 74310 by rahul123_libra on Thursday 9th of June 2005 02:30:46 AM
Old 06-09-2005
Tools

Have cron run a script on days 28, 29, 30 and 31 of every month.
Create two variables in the script, one containing today's day of the
month and another containing tomorrow's day of the month:

Code:
 TODAY=`date +%d`
 TOMORROW=`date +%d -d "1 day"`

 # See if tomorrow's day is less than today's
 if  [  $TOMORROW  -lt  $TODAY  ];  then
         echo  "This is the last day of the month"
 #       Do stuff...
 fi

Smilie

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

Last edited by zaxxon; 10-20-2011 at 04:54 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
crontab(1)						      General Commands Manual							crontab(1)

NAME
crontab - user job file scheduler SYNOPSIS
[file] [username] [username] [username] DESCRIPTION
The command manages a crontab file for the user. You can use a crontab file to schedule jobs that are executed automatically by (see cron(1M)) on a regular basis. The command has four forms: Create or replace your crontab file by copying the specified file, or standard input if file is omitted or is specified as file, into the crontab directory, The name of your crontab file in the crontab directory is the same as your effective user name. If the compartmentalization feature is enabled, the crontab file is your effective user name followed by a colon followed by the compartment id from which the crontab file is created. Edit a copy of the user's crontab file, or create an empty file to edit if the crontab file does not exist. When editing is complete, the file will be copied into the crontab directory as the user's crontab file. If the compartmentalization feature is enabled, it only edits a copy of the user's crontab file from the compartment that the crontab files were created from. Lists the user's crontab file. If the compartmentalization feature is enabled, it only lists the crontab files from the compartment that the crontab files were created from. Remove the user's crontab file from the crontab directory. If the compartmentalization feature is enabled, it only removes the crontab files from the compartment that the crontab files were created from. Only a privileged user can use username following the or options, to edit, list, or remove the crontab file of the specified user. The entries in a crontab file are lines of six fields each. The fields are separated by spaces or tabs. The lines have the following for- mat: minute hour monthday month weekday command The first five are integer patterns that specify when the sixth field, command, should be executed. They can have the following ranges of values: minute The minute of the hour, hour The hour of the day, monthday The day of the month, month The month of the year, weekday The day of the week, Each pattern can be either an asterisk meaning all legal values, or a list of elements separated by commas. An element is either a number in the ranges shown above, or two numbers in the range separated by a hyphen (meaning an inclusive range). Note that the specification of days can be made in two fields: monthday and weekday. If both are specified in an entry, they are cumulative. For example, runs command at midnight on the first and fifteenth of each month, as well as every Monday. To specify days in only one field, set the other field to asterisk For example, runs command only on Mondays. The sixth field, command (the balance of a line including blanks in a crontab file), is a string that is executed by the shell at the spec- ified times. A percent character in this field (unless escaped by a backslash is translated to a newline character, dividing the field into "lines". Only the first "line" (up to a or end-of-line) of the command field is executed by the shell. Any other "lines" are made available to the command as standard input. Blank lines and those whose first non-blank character is will be ignored. invokes the command from the user's directory with the POSIX shell, It runs in the queue (see queuedefs(4)). supplies a default environment for every shell, defining: Users who desire to have their executed must explicitly do so in the crontab entry or in a script called by the entry. You can execute if your name appears in the file If that file does not exist, you can use if your name does not appear in the file If only exists and is empty, all users can use If neither file exists, only the user can use The files consist of one user name per line. Security Restrictions If the compartmentalization feature is enabled, and invoke the jobs from the compartment that the jobs were created from. Note that cre- ates the job files in Hence, if the command is invoked from a compartment which has no write access to this directory and which disallows the privilege, fails to schedule the jobs. See compartments(5) and privileges(5) for more information. EXTERNAL INFLUENCES
Environment Variables determines the interpretation of text within file as single and/or multibyte characters. determines the language in which messages are displayed. If or is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty variable. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, behaves as if all internationalization variables are set to "C". See environ(5). determines the editor to be invoked when option is specified. The default editor is vi. International Code Set Support Single-byte and multibyte character code sets are supported. WARNINGS
Be sure to redirect the standard output and standard error from commands. If this is not done, any generated standard output or standard error is mailed to the user. FILES
Main cron directory List of allowed users List of denied users Accounting information Directory containing the crontab files SEE ALSO
sh(1), cron(1M), queuedefs(4), compartments(5), privileges(5). STANDARDS CONFORMANCE
crontab(1)
All times are GMT -4. The time now is 06:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy