logo
down
shadow

How do I run a script for 1st working day of every month in cron?


How do I run a script for 1st working day of every month in cron?

By : Vlad
Date : November 18 2020, 11:13 AM
I hope this helps you . I have to set the cronjob for 1st working day of every month which means the script should run on 1st working day of every month. , First, run the date command:
code :
$ date '+%x'
12/29/2014
$ cat holidays
01/01/2015
07/04/2015
#!/bin/sh
dom=$(date '+%d') # 01-31, day of month
year=$(date '+%Y') # four-digit year
month=$(date '+%m') # two-digit month

nworkdays=0
for d in $(seq 1 $dom)
do
    today=$(date -d "$year-$month-$d" '+%x') # locale's date representation (e.g. 12/31/99)
    dow=$(date -d "$year-$month-$d" '+%u')   # day of week: 1-7 with 1=Monday, 7=Sunday
    if [ "$dow" -le 5 ]  && grep -vq "$today" /path/holidays
    then
        workday=Yes
        nworkdays=$((nworkdays+1))
    else
        workday=
    fi
done
[ "$workday" ] && [ "$nworkdays" -eq 1 ] && /path/command


Share : facebook icon twitter icon
Cron job to run a script at the begining of the month

Cron job to run a script at the begining of the month


By : vivek.kartha
Date : March 29 2020, 07:55 AM
I hope this helps . I would like to write a cron job that has to run a PHP script on the 1st day of each month. , Add to crontab -e this:
code :
0 0 1 * * php /path/to/script.php
How can i run a php script on a server every month without running a cron job. e.g. using .htaccess

How can i run a php script on a server every month without running a cron job. e.g. using .htaccess


By : Kevin Sta. Ana
Date : March 29 2020, 07:55 AM
To fix this issue You can use some web cron service. I'm not going to propose any particular one, just search for web cron yourself.
Set Cron Job for 1st working day of every month in Shell Scripting

Set Cron Job for 1st working day of every month in Shell Scripting


By : Sam
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I'm new to scripting language, can anyone please explain how to set the cron job for 1st working day? , First, run the date command:
code :
$ date '+%x'
> 12/29/2014
$ cat holidays
> 01/01/2015
> 07/04/2015
#!/bin/sh
dom=$(date '+%d') # 01-31, day of month
year=$(date '+%Y') # four-digit year
month=$(date '+%m') # two-digit month

nworkdays=0
for d in $(seq 1 $dom)
do
    today=$(date -d "$year-$month-$d" '+%x') # locale's date representation (e.g. 12/31/99)
    dow=$(date -d "$year-$month-$d" '+%u')   # day of week: 1-7 with 1=Monday, 7=Sunday
    if [ "$dow" -le 5 ]  && grep -vq "$today" /path/holidays
    then
        workday=Yes
        nworkdays=$((nworkdays+1))
    else
        workday=
    fi
done
[ "$workday" ] && [ "$nworkdays" -eq 1 ] && /path/command
How to define a cron expression that execute a script in the first monday of each month?

How to define a cron expression that execute a script in the first monday of each month?


By : distr0yer
Date : March 29 2020, 07:55 AM
like below fixes the issue The first monday of the month is the only monday that occurs during the first seven days of the month. Thus, to execute the job at 1:02 AM, use:
code :
2 1 1-7 * * test $(date +\%u) -eq 1 && path/to/my/script.sh
2 1 * * Mon  test $(date +\%e) -le 7 && path/to/my/script.sh
Cron Expression is not working for last day of the month

Cron Expression is not working for last day of the month


By : Roni Menkin
Date : March 29 2020, 07:55 AM
will be helpful for those in need I want to schedule a task to run on last day of every month at 10:10 AM. The cron expression is 0 10 10 L * ? , This Schedule runs on the last day of the month an 10:10AM:
Related Posts Related Posts :
  • Security of su root in bash script
  • how to replace a string at a specific position in a csv file using bash
  • how to delete duplicate lines in a text file in unix bash?
  • Compare a variables in bash
  • How do I use sed on a string?
  • Using bash variables for range in sed
  • convert a DURATION HH:MM:SS to seconds in bash
  • Shell make system paths click-able when printed out by my shell script
  • I want to use parallel-ssh to run a bash script on multiple servers, but it simple prints the echo statements
  • AWK between 2 patterns - first occurence
  • Nginx on docker - daemonize and attach to bash
  • Delete or Replace nth line in a file after a pattern match using shell scripts
  • Actual return code for SCP
  • How to exit a bash function that expects a return
  • Bash script to split file into two files while changing output file during processing
  • Pass command line arguments via sbatch
  • variable substitution (what do you call/name this method)?
  • Call function from another shell script
  • How to Grep and Replace With Exclusions
  • shell command to remove characters after a special character in bash/shell
  • Bash Unexpected End of File Error After Installing RVM
  • Nested Loop with increment on inner loop?
  • video orientation detection in bash
  • Interrupt sleep in bash with a signal trap
  • Want file rename script to add number at end with fixed length
  • What's the DRYest way to replace a file with a symlink in bash
  • How to run Bitcoin's autogen.sh file?
  • Renaming files in folder and subfolders using a list- Bash Script/Unix
  • Bash command to compare more than two files
  • If It is a directory append text
  • What's wrong with my WHILE-DO loop, or why my script can't find the file I'm giving it on a plate?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org