Skip to content

Python: Script that Execute the First Tuesday After First Monday of the Month

December 24, 2015

In the post “Python: Script that Execute the First Tuesday of the Month” I explained how to call a Python script as a cronjob to execute a shell script only the first Tuesday of each month.

After a few month of implemented we realized that the requirement was not correctly stated. The execution of the script is dependent of data files been uploaded to the UNIX machine, those data files are uploaded the first Monday of each month. The original Python script was:

#!/usr/bin/python

import datetime, subprocess

daynum = datetime.datetime.today().day
command_line = [“/bin/ksh”, “-c”, “/dwprod/scripts/jPostDschCallPCM.sh”]

if daynum < 8:
subprocess.call(command_line)

If the first Tuesday of the Month is also the first day of the month, the data files will not be found and the shell script executed will fail.

To solve the problem, the new requirement can be to execute the shell script the first Tuesday after the first Monday of the month.

And can be implemented with the following minimal modification:

#!/usr/bin/python

import datetime, subprocess

daynum = datetime.datetime.today().day
command_line = [“/bin/ksh”, “-c”, “/dwprod/scripts/jPostDschCallPCM.sh”]

if daynum > 1 daynum <= 8:
subprocess.call(command_line)

Again, I’m amazed how easy was using Python to adapt to the new requirement.

Advertisements

From → Python, UNIX

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: