What's new

Cron job to run first Monday each month (SOLVED)

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Indyman

Occasional Visitor
Hello - I created the cronjob for my Netgear R7000 in an attempt to get it to run the script wol_nas on the first Monday of each month at 7:50pm:
cru a Mon_NAS_on "50 19 1-7 * * [ "$(date '+\%a')" == "Mon"] && /jffs/scripts/wol_nas.sh"
Unfortunately this doesn't work. Also when I execute "cru l" in the router the output is "50 19 1-7 * * [ \Fri == Mon] && /jffs/scripts/wol_nas.sh #Mon_NAS_on#" (note this was run on a Sunday ). What am I missing in my syntax? The wol_nas script should run when the day of the month is between 1-7 and when (date + \%a) = "Mon"? Thanks
 
Asuswrt-Merlin is not supported on Netgear hardware. Perhaps you should ask in the Netgear forum.
Probably the Vortex fork. That being said moving the eval to the script will work, as when adding to cru it's evaluating it at that time, rather than on scheduled call.
 
cru a Mon_NAS_on "50 19 1-7 * * [ "$(date '+\%a')" == "Mon"] && /jffs/scripts/wol_nas.sh"
Try this, runs Mon if day of month is less or equal to 7:
Code:
cru a Mon_NAS_on "50 19 * * Mon [ \"\$(date +%d)\" -le 07 ] && /jffs/scripts/wol_nas.sh"
 
Ah, I didn't know escaping characters was a possibility. Makes sense!
Escaping keeps the ", so it can run the evaluation [ "$(date +%d)" -le 07 ].
 
Try this, runs Mon if day of month is less or equal to 7:
Code:
cru a Mon_NAS_on "50 19 * * Mon [ \"\$(date +%d)\" -le 07 ] && /jffs/scripts/wol_nas.sh"
Hi thelonelycoder - thanks for your response - interesting solution. Wouldn't you need to also escape the %d as well?
 
Hi thelonelycoder - thanks for your response - interesting solution. Wouldn't you need to also escape the %d as well?
Test it, it works as posted.
Remove old job with:
Code:
cru d Mon_NAS_on
Then add it with my posted line:
Code:
cru a Mon_NAS_on "50 19 * * Mon [ \"\$(date +%d)\" -le 07 ] && /jffs/scripts/wol_nas.sh"
Then check with:
Code:
cru l
You'll see:
Code:
50 19 * * Mon [ "$(date +%d)" -le 07 ] && /jffs/scripts/wol_nas.sh #Mon_NAS_on#
which is a valid job.
 
Remember - there's no RTC, so watch out for reboots and the back to the future impact of the built-in time/data stamp before NTP updates to real time...
 
Remember - there's no RTC, so watch out for reboots and the back to the future impact of the built-in time/data stamp before NTP updates to real time...
The statement is only run at 19:50 on a Monday. Very unlikely this happens at boot, before NTP kicks in.
Merlin starts at August 1 00:00 and john some other time but far away from 7 PM.
 
Test it, it works as posted.
Remove old job with:
Code:
cru d Mon_NAS_on
Then add it with my posted line:
Code:
cru a Mon_NAS_on "50 19 * * Mon [ \"\$(date +%d)\" -le 07 ] && /jffs/scripts/wol_nas.sh"
Then check with:
Code:
cru l
You'll see:
Code:
50 19 * * Mon [ "$(date +%d)" -le 07 ] && /jffs/scripts/wol_nas.sh #Mon_NAS_on#
which is a valid job.
thelonelycoder - yep looks just like you said with "cru l" - thank you (and hopefully no offense taken)! Looking forward to this running next Monday. Appreciate everyone's responses and helpful comments - thanks again.
Update: the script executed tonite at 7:50PM - woo hoo!
 
Last edited:

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top