Setting Cron Job Runs on Monday of Every Third Thursday

Abstract: Solve the inability of standard cron to schedule tasks for the third Thursday of each month by using a shell script wrapper that filters daily runs based on date logic.

Created: 2026-09-27 by
To schedule a cron job for the third Thursday of every month, you must use a shell script wrapper because standard cron syntax cannot calculate relative dates like "third" or "last." The most robust method involves adding a single cron entry that runs daily at your desired time, executing a small script that checks if today is a Thursday and if it falls within the 15th to 21st day range. This approach ensures the task executes exactly once per month on the correct weekday without complex mathematical modulo operations that often fail on edge cases.

Understanding Cron Limitations

Cron jobs are powerful tools for automation in Unix-like systems, but they operate on fixed fields: minute, hour, day of month, month, and day of week. While you can specify 0 9 * * 4 to run a command at 9 AM every Thursday, this will trigger seven times a month. There is no native cron field that accepts expressions like "the third occurrence" of a weekday. Attempting to solve this with pure cron arithmetic (using modulo operators) is error-prone and difficult to maintain. Therefore, the industry standard solution is to delegate the date logic to a simple shell script.

Creating the Detection Script

The core of this solution is a bash script that determines if the current day meets two criteria: it is a Thursday, and it is between the 15th and 21st of the month. You can create this script in your home directory or a dedicated bin folder. Create a file named third_thursday_job.sh using your preferred text editor.

#!/bin/bash

# Get the current day of the week (0=Sun, 1=Mon, ..., 4=Thu)
DAY_OF_WEEK=$(date +%u)

# Get the current day of the month
DAY_OF_MONTH=$(date +%d)

# Check if it is Thursday (4) and between the 15th and 21st
if [ "$DAY_OF_WEEK" -eq 4 ] && [ "$DAY_OF_MONTH" -ge 15 ] && [ "$DAY_OF_MONTH" -le 21 ]; then
    # Replace this line with your actual command
    echo "Running third Thursday job at $(date)" >> /var/log/third_thursday.log
    
    # Example: /usr/bin/your_command_here
fi

This script uses the date command with format codes %u for the numeric day of the week (where Monday is 1 and Thursday is 4) and %d for the day of the month. The conditional statement ensures that even if the cron daemon triggers the script every day, the actual work only happens when both conditions are true. If the day is not a Thursday, or if it is the first, second, fourth, or fifth Thursday, the script exits silently.

Scheduling the Wrapper

Once the script is created, you need to make it executable and add it to your crontab. First, ensure the script has execution permissions by running chmod +x ~/third_thursday_job.sh. Next, edit your user's crontab by typing crontab -e.

Add the following line to run the script every day at 9:00 AM:

0 9 * * * /home/your_username/third_thursday_job.sh

By scheduling the script to run daily, you cover all days of the week. The logic inside the script handles the filtering. This method is significantly more reliable than trying to manipulate the day-of-month field directly, as it avoids issues with months that have varying numbers of days or leap years. For related scheduling challenges, such as running jobs on specific weekdays like Monday and Thursday, you might find our guide on Setting Cron Job Runs on Monday of Week 3 and Thursday helpful for understanding broader scheduling patterns.

Handling Time Zones and Paths

When working with cron jobs, environment variables are often limited compared to an interactive shell session. It is critical to use absolute paths for both the interpreter (/bin/bash) and any commands executed within the script. If your job relies on external services or scripts located in non-standard directories, always provide the full path. Additionally, be aware that the system's local time zone applies to the date command unless overridden. If your server is set to UTC but you want the job to run based on local business hours, you may need to adjust the TZ environment variable within the script or export it in the crontab header.

Testing and Verification

Before relying on this setup in production, test the logic manually. Run the script directly from the command line: ~/third_thursday_job.sh. Check the log file specified in the script to see if it recorded the execution. To verify the date logic without waiting for the actual day, you can temporarily modify the DAY_OF_MONTH variable in the script to match today's date and run it again. Once verified, remove the test modifications and let the cron daemon handle the timing. For users concerned about privilege escalation during these automated tasks, reviewing best practices for running programs with elevated privileges can prevent security pitfalls, as detailed in our article on Run Programs with Elevated Privileges: A Comprehensive Guide.

Frequently Asked Questions

Can I do this with pure cron syntax?

No, standard cron does not support relative date calculations like "third Thursday." You must use a script wrapper to evaluate the date dynamically. Any attempt to use modulo arithmetic in cron fields will likely result in incorrect execution frequencies.

What if my server timezone is different from my local time?

The date command respects the system's configured timezone. If your server is in UTC but you need Eastern Time, set the TZ variable in your crontab or script before calling date, ensuring the job runs at the intended local hour.

How do I debug why my script isn't running?

Check the system mail logs or the cron log file (often /var/log/syslog or /var/log/cron). Ensure the script has executable permissions and uses absolute paths for all binaries. Redirect stderr to a log file in the crontab line to capture errors.

Can I run this job weekly instead of monthly?

If you want the third Thursday of every week, you would need a different logic check. However, the concept remains the same: use a daily cron trigger and filter by week number or consecutive day counts within the script, as cron cannot natively distinguish between "week 3" globally.

Is there a risk of the job running twice?

If the script takes longer than one minute, it could theoretically overlap with the next cron tick if not managed. Use a lock file mechanism or flock to ensure only one instance runs at a time, preventing duplicate executions during long-running tasks.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More