Guides Basics
How to make a cron job skip public holidays
Short answer: Cron has no built-in public holiday calendar, so it cannot skip holidays on its own. A crontab entry only understands minutes, hours, days of the month, months and days of the week. You have two reliable options: add a holiday check to the top of your cron script that calls the Netsware API (GET /v1/check) and exits on non-working days, or run the cron job on Netsware with a business-hours schedule, so a run that falls on a public holiday moves to the next business day. Neither option requires you to maintain a holiday list.
Why cron has no holiday calendar
This crontab entry runs at 09:00 from Monday to Friday:
0 9 * * 1-5 /opt/jobs/send-invoices.shThat is the limit of what cron can express. On its own, it cannot account for:
- Moving holidays. Easter and Lunar New Year change date every year, and governments add one-off holidays at short notice.
- Country-specific calendars. A job that serves customers in the UK, Germany and India needs three holiday calendars, plus regional calendars in some countries.
- Different weekends. In Saudi Arabia the weekend is Friday and Saturday, so
1-5runs on the wrong days. - Time zones and daylight saving. Cron follows the server clock, usually UTC. When London or New York change their clocks, a 09:00 local job drifts by an hour unless you edit the crontab twice a year.
Every workaround based on a local holiday file has the same weakness: someone must update it for every country, every year. The first time it is missed, the job runs on a holiday.
Option 1: Add a holiday check to your cron script
Keep your crontab unchanged. At the top of the script, ask Netsware whether today is a working day and exit quietly if it is not:
#!/usr/bin/env bash
set -euo pipefail
command -v jq >/dev/null || { echo "jq is required for the Netsware check" >&2; exit 1; }
# Ask Netsware: is today a working day in the UK? (00:00 to 23:59 = only weekends and holidays matter)
resp=$(curl -fsS --max-time 10 \
-H "X-API-Key: $NETSWARE_KEY" \
"https://app.netsware.com/v1/check?country=GB&timezone=Europe/London&open_time=00:00&close_time=23:59")
if [ "$(echo "$resp" | jq -r '.open')" != "true" ]; then
echo "Skipping: $(echo "$resp" | jq -r '.reason')" # e.g. weekend or public_holiday
exit 0
fi
# ... your job runs here
/opt/jobs/send-invoices-now.shHow the script behaves:
- On a working day,
openistrueand the job runs. - On a weekend or public holiday, the script prints the reason (
weekendorpublic_holiday) and exits without running the job. - If the check fails (no network or an invalid key),
curl -fandset -estop the script with an error, so the job never runs without a confirmed answer. Your cron mail or monitoring reports the failure. - If jq is missing, the script stops with an error instead of skipping silently.
To check real opening hours instead of the whole day, use your own times, for example open_time=09:00&close_time=18:00. For a Friday and Saturday weekend, add &days=SUN,MON,TUE,WED,THU.
The range 00:00 to 23:59 covers the whole day except its last minute (23:59 counts as closed), so do not schedule the job at 23:59.
Cost: each check is one API request against your plan's monthly quota (20,000 on the free plan). A daily cron job uses about 30 requests a month.
The same check works anywhere you can run curl, including a Kubernetes CronJob, a scheduled GitHub Actions workflow (which runs in UTC unless you set a timezone) and a Windows scheduled task with PowerShell.
Option 2: Run the cron job on Netsware
If your cron job only calls a URL (an internal endpoint, a webhook or a "run now" API), you can remove the crontab and let Netsware call that URL on schedule. Holiday handling, time zones and failure alerts are built in, and there is no server to keep running.
Step 1: Define your business days and hours
curl -X POST https://app.netsware.com/v1/schedules \
-H "X-API-Key: $NETSWARE_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "UK working hours",
"country_code": "GB",
"timezone": "Europe/London",
"days": ["MON","TUE","WED","THU","FRI"],
"open_time": "09:00",
"close_time": "18:00",
"respect_holidays": true
}'Use real opening hours here, not 00:00 to 23:59. A run that is held back fires at the schedule's next opening minute, so a 00:00 opening would make it fire at midnight.
Step 2: Create the job with your cron expression
curl -X POST https://app.netsware.com/v1/jobs \
-H "X-API-Key: $NETSWARE_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "recurring",
"name": "Send invoices",
"url": "https://internal.example.com/jobs/send-invoices",
"method": "POST",
"timezone": "Europe/London",
"cron": "0 9 * * MON-FRI",
"business_hours_schedule_id": "sch_..."
}'The cron expression runs in the job's timezone, so 09:00 stays 09:00 in London across daylight saving changes. When 09:00 falls on a bank holiday, Netsware holds the run and fires it at the next opening minute, 09:00 on the next business day. The run is logged with its reason (for example public_holiday) and is not counted as a failure.
To add holiday handling to an existing Netsware job, send PUT /v1/jobs/{id} with {"business_hours_schedule_id": "sch_..."}.
Which option should you choose?
| Option 1: check in your script | Option 2: run the job on Netsware | |
|---|---|---|
| A run on a holiday | is skipped | moves to the next business day |
| Where the job runs | on your server, as today | Netsware calls your URL |
| Daylight saving | follows your server clock | handled in the job's timezone |
| When a run fails | you build alerts and retries | a failure alert (email on every plan), then the next scheduled run |
Choose Option 1 when the job must run on your own server. Choose Option 2 when the job is a URL call and you want holiday-aware scheduling, failure alerts and run history without maintaining a server.
Do you need a public holiday API or business-aware job scheduling?
These solve different problems, so start from what your job actually needs.
- Only public holiday dates. A dedicated holiday data API may be all you need. Free options such as Nager.Date provide public holiday data for over 200 countries, including state and provincial calendars. Check the supported countries, regional coverage and data availability for the markets you serve.
- Whether a business is open right now. You also need working days, opening hours and the business's own timezone, including daylight saving. Netsware's
GET /v1/checkanswers this in one request. - HTTP jobs that wait for the next opening minute. You need scheduling and execution, not only data. Netsware calls your URL, moves runs that fall on a holiday or outside business hours to the next opening minute, and handles failure alerts and execution history, with retries for one-time jobs.
| What your job needs | A holiday data API | Netsware |
|---|---|---|
| Public holiday dates | yes | yes, 226 countries and territories |
| "Open right now?" in the business's local time | your own business-hours and timezone logic | one request to GET /v1/check |
| Country-specific weekends | some APIs provide weekend data; your code applies the rules | set per schedule |
| Opening and closing hours | your code | built in |
| Timezone and daylight saving | your code | built in |
| Runs that wait for the next opening minute | your own scheduling logic | built in |
| HTTP execution and failure alerts | extra infrastructure | built in |
FAQ
Is Sunday 0 or 7 in cron?
Both. In standard cron, 0 and 7 both mean Sunday, and most implementations, including Netsware, also accept SUN. Monday is 1, so 1-5 runs Monday to Friday.
Are cron jobs still used?
Yes. Cron is still the standard scheduler on Linux and macOS, and the same five-field syntax drives Kubernetes CronJobs, scheduled GitHub Actions workflows and most cloud schedulers. Cron handles time-based execution, but it has no built-in public holiday calendar or business-hours rules; those need extra logic or a holiday API.
Is there a free API to check whether today is a public holiday?
Yes. Free holiday data APIs such as Nager.Date cover over 200 countries; check that the countries and regional calendars you need are supported. If you also need opening hours, country-specific weekends or jobs that wait for the next business day, that is what Netsware adds, and its free Essentials plan covers 10 countries.
Can cron skip weekends?
Yes. A day-of-week field such as 1-5 runs Monday to Friday. Cron does not know country-specific weekends, so 1-5 is wrong in countries with a Friday and Saturday weekend, and public holidays need extra calendar logic.
How do I run a cron job only on business days?
Add a Netsware check to the top of the script and exit when open is false, or run the job on Netsware with a business-hours schedule. Both treat weekends and public holidays as non-working days.
Can I keep a holiday file on the server instead?
You can, but someone must update it every year for every country, including holidays announced at short notice. Netsware covers 226 countries and territories, so there is no list to maintain.
Which countries are covered?
226 countries and territories, including regional and state holidays where they apply. The free Essentials plan includes 10 holiday countries: the US, India, the UK, Germany, France, Canada, Australia, Japan, Singapore and Brazil. Paid plans include all 226. GET /v1/hours/meta/countries returns each country's usual weekend.
Can I get the list of public holidays for a country?
Yes. GET https://app.netsware.com/v1/holidays?country=GB&year=2026 returns every public holiday for that year with its date and name.
Does it cost anything?
The Netsware Essentials plan is free forever and does not require a credit card. It includes business-hours checks, scheduled jobs and holiday calendars for 10 countries; paid plans add higher limits and all 226.
Summary
Cron answers "what time is it?" but not "is today a working day here?". To make a cron job skip public holidays, add a Netsware check to the top of the script, or run the job on Netsware so holiday runs move to the next business day, in the correct timezone, with failure alerts built in.
Related guides: How to run a webhook only during business hours · How to skip public holidays in an n8n workflow
Start free. No credit card, no trial period. The Essentials plan is free forever, so you can build and test your software, apps and workflows for as long as you need, and upgrade only when you are ready.
Start freeSpotted a mistake or something out of date? Tell us and we will fix it.
Keep reading
Run webhooks in business hours
Cron cannot limit a webhook to business hours or skip public holidays. Attach the job to a Netsware business-hours schedule and runs wait until the business opens.
Send SendGrid emails in business hours
SendGrid cannot skip public holidays. Check each recipient's business hours with Netsware and set send_at, or let a Netsware job send campaigns on working days.
Use each contact's hours in HubSpot
HubSpot does not know each country's public holidays. A custom code action asks Netsware if a contact's business is open and delays the action until it opens.