What's new

Help with modifying the lights-on lights-off cron job.

  • 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!

Damob9K

New Around Here
Hi all,

I have had the lights-on / lights-off cron job running for a few months now (thanks Merlin !) but wanted to change it a little ...
I had it so that it turned on the lights at 17:00 every day, and turned them off at 00:00.
It also sends a WOL signal to my server at 17:30

But what I would like to change it to, is :
Turn on at 17:00 Mon - Friday .... turn off at 00:00
Turn on at 9:00 Sat - Sun .... turn off at 00:00

So after reading a bit more about cron, I came up with the following :

#!/bin/sh
cru a lightsoff "0 00 * * * /jffs/scripts/ledsoff.sh"
cru a lightson "00 17 * * 1-5 /jffs/scripts/ledson.sh"
cru a lightson "00 09 * * sat,sun /jffs/scripts/ledson.sh"

cru a WOL "30 17 * * * /usr/bin/ether-wake -b -i br0 xx:xx:xx:xx:xx:21"

But .. this seems to have broken it all, as now the lights are not coming on ever ! - btw as I type this it's 18:00 on the Sunday, so i'm not sure what it will do tomorrow !

NB I originally had 6,0 in the part for the weekend but as that didn't work,I changed to sat,sun.
I have rebooted each time before anyone asks :)

Please can some one help me !! I assume I have the format or syntax wrong, but i'm no expert in Unix commands.
Many thanks

Damob
 
From the crontab doc (cru is just a frontend for crontab)
Names can also be used for the ``month'' and ``day of week'' fields. Use the first three letters of the particular day or month (case doesn't matter). Ranges or lists of names are not allowed.

You also cannot have the same name for two entries. Try changing the Sat,Sun entry to

cru a lightson67 "00 09 * * 6-7 /jffs/scripts/ledson.sh"

(Sunday can be represented by either 0 or 7)
 
(Sunday can be represented by either 0 or 7)
From my experiences 0 is the better option for Sunday, as depending on Web-UI language chosen, 7 will not work for some.
 
OK .. Thanks guys.

I've tried 3 combinations : 6-7 / 6,0 / 0,6 but none work :(
Here's what i have:
#!/bin/sh
cru a lightsoff "0 00 * * * /jffs/scripts/ledsoff.sh"
cru a lightsonwd "0 17 * * 1-5 /jffs/scripts/ledson.sh"
cru a lightsonwe "0 9 * * 6-7 /jffs/scripts/ledson.sh"

It's on a Asus RT-N66U if that's of any help.

would it matter what order they are in ?
Thanks again.
 
That should work....How are you testing? For the weekend rule to fire, you'll now need to wait until next weekend.

Also, does the following command show your jobs?

cru l (that's a small letter l)

As a final check, make sure you didn't edit it in the wrong format. Run dos2unix against your script file.
 
cru l (that's a small letter l)

As a final check, make sure you didn't edit it in the wrong format. Run dos2unix against your script file.
Gee, you're fast. Wanted to say the same.
Make sure the line endings EOL is in UNIX format.​
 
Um ... sorry for my ignorance ... would the lightsonwe not run as it's gone 9:00 ? or does it only run at that specific time ?
I'm editing the services-start from within WinSCP - then rebooting the router, should I be doing it another way ?

More thanks :)
 
It runs exactly at that time - once.
This website is a great generator. Altough not all quirks work with the cron manager on asus:
http://crontab.guru/
 
Ah I see (the penny drops) .... so the last cron job that ran before i started to fuddle with it was to turn off the leds, I will need to wait till tomorrow at 17:00 for them to turn back on, and then to Saturday at 9:00 to see if they turn on as expected.
I sort of assumed that when I rebooted the router it would process the last relevant job.
OK so I'll have to wait until tomorrow to see if at least the weekday job is still functioning !
Thanks again for your advise, I should of stopped and thought about how cron works before going full steam ahead into the abyss - but where's the fun in that :)

Cheers
 
It runs exactly at that time - once.
And no provision for making up 'missed' events....so next run will be next weekend for the weekend job.
Um ... sorry for my ignorance ... would the lightsonwe not run as it's gone 9:00 ? or does it only run at that specific time ?
I'm editing the services-start from within WinSCP - then rebooting the router, should I be doing it another way ?

More thanks :)
If you are using the WinSCP internal editor, you should be OK. If you changed to another editor for WinSCP, you need to make sure it's operating in Linux format for line endings.
 
Also, you can run the script directly in the terminal:
sh /jffs/scripts/yourscriptname
Be aware that you add them to the crontab
If you want to delete one, use
cru d name
Where name is e.g. lightsoff
 
You could also temporarily change the time for the weekend job to sometime in the future (instead of 9:00) to verify it fires, then change it back.
 
Ha ha .. thanks john .. hadn't thought of that .. simple and effective ! - just like me less the effective part :)
Thanks again guys, I need to go off a cook some food, will try this later.

Very very many thanks for both of your help.
 

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

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