Cron job not running

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Author Message
miggalvez
DD-WRT Novice


Joined: 15 Dec 2016
Posts: 19

PostPosted: Sun Dec 18, 2016 12:19    Post subject: Cron job not running Reply with quote
I'm trying to run a cron job that updates a gen_host.txt file that blocks ads in my network.

I added the following line to the Additional Cron Jobs field in the Administration>Management tab, cron section (cron is enabled):

0 1 * * * root /jffs/gen_host.sh

I added the gen_host.sh file with the script to the jffs folder. I checked and it is there:

-rw-r--r-- 1 root root 6760 Dec 17 06:33 gen_host.sh

JFFS2 support is enabled.

Well, the cron job doesn't seem to be running. According to the logs and the time stamp of the file, the gen_host.txt file is not updated.

Am I missing something?
Sponsor
miggalvez
DD-WRT Novice


Joined: 15 Dec 2016
Posts: 19

PostPosted: Mon Dec 19, 2016 12:05    Post subject: Reply with quote
I got it to work. It seems that cron doesn't like the sh extension on scripts.

I also made sure that it had executable permissions. chmod +x /jffs/gen_host
Alozaros
DD-WRT Guru


Joined: 16 Nov 2015
Posts: 6437
Location: UK, London, just across the river..

PostPosted: Tue Dec 20, 2016 9:24    Post subject: Reply with quote
well there are variety of ADblocking scripts
but the cron job to update host files is all the same

0 12 * * * root /tmp/.rc_startup

_________________
Atheros
TP-Link WR740Nv1 ---DD-WRT 55630 WAP
TP-Link WR1043NDv2 -DD-WRT 55723 Gateway/DoT,Forced DNS,Ad-Block,Firewall,x4VLAN,VPN
TP-Link WR1043NDv2 -Gargoyle OS 1.15.x AP,DNS,QoS,Quotas
Qualcomm-Atheros
Netgear XR500 --DD-WRT 55779 Gateway/DoH,Forced DNS,AP Isolation,4VLAN,Ad-Block,Firewall,Vanilla
Netgear R7800 --DD-WRT 55819 Gateway/DoT,AD-Block,Forced DNS,AP&Net Isolation,x3VLAN,Firewall,Vanilla
Netgear R9000 --DD-WRT 55779 Gateway/DoT,AD-Block,AP Isolation,Firewall,Forced DNS,x2VLAN,Vanilla
Broadcom
Netgear R7000 --DD-WRT 55460 Gateway/SmartDNS/DoH,AD-Block,Firewall,Forced DNS,x3VLAN,VPN
NOT USING 5Ghz ANYWHERE
------------------------------------------------------
Stubby DNS over TLS I DNSCrypt v2 by mac913
miggalvez
DD-WRT Novice


Joined: 15 Dec 2016
Posts: 19

PostPosted: Tue Dec 20, 2016 11:31    Post subject: Reply with quote
Alozaros wrote:
well there are variety of ADblocking scripts
but the cron job to update host files is all the same

0 12 * * * root /tmp/.rc_startup


The way this one works is a bit different. Here are the instructions (I'm also attaching the script):

Quote:
## gen_hosts by IronManLok
##
## Downloads domain entries of known ad abusers from multiple sources,
## cleans up, merges and removes duplicates. Includes white-listing and
## custom host entries.
##
## This script is intended to be used on units running DD-WRT, it requires
## the use of JFFS (or USB drive mounted on /jffs) and DNSMasq as DNS server.
##
## On Services Tab, at Additional DNSMasq options, add this line:
## addn-hosts=/tmp/gen_host.txt
##
## Call this script from your firewall script. Also, use cron to schedule its
## execution. For running everyday at 22:00:
## 0 22 * * * root /jffs/gen_host
##
## For white-listing, create /jffs/whitelist_hosts.txt and list one domain
## per line. For custom hosts entries, create /jffs/my_hosts.txt and
## add any lines in the same format of a regular hosts file.
Xentrk
DD-WRT Novice


Joined: 03 Jun 2016
Posts: 45

PostPosted: Mon Jan 02, 2017 7:09    Post subject: Reply with quote
miggalvez wrote:
I got it to work. It seems that cron doesn't like the sh extension on scripts.

I also made sure that it had executable permissions. chmod +x /jffs/gen_host


Thank you, thank you, thank you. Removing the .sh from the file name fixed my cron issues too. I never would have thought to try that. I have been banging my head against the wall and looking at the forums for awhile now. Glad I found your post!
feichter
DD-WRT Novice


Joined: 31 Aug 2012
Posts: 13

PostPosted: Thu Dec 09, 2021 11:52    Post subject: For a Buffalo Buffalo WZR-HP-G300 running v3.0 (build 44715) Reply with quote
For cron jobs to execute .sh files properly make sure you include the FULL path to sh!

* * * * * root /bin/sh /jffs/www/send.sh
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1857
Location: Hung Hom, Hong Kong

PostPosted: Thu Dec 09, 2021 13:05    Post subject: Reply with quote
DD-WRT uses ash not bash. So be careful with the first line of your script.sh.

And script.sh also needs execute permission.


_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 14219
Location: Texas, USA

PostPosted: Thu Dec 09, 2021 17:32    Post subject: Reply with quote
Nice necro. Anyway, the only targets that bash compatibility is not enabled on is micro. All other targets have bash compatibility configured in busybox in DD-WRT.
_________________
"Life is but a fleeting moment, a vapor that vanishes quickly; All is vanity"
Contribute To DD-WRT
Pogo - A minimal level of ability is expected and needed...
DD-WRT Releases 2023 (PolitePol)
DD-WRT Releases 2023 (RSS Everything)

----------------------
Linux User #377467 counter.li.org / linuxcounter.net
MesMurized
DD-WRT User


Joined: 08 Aug 2017
Posts: 84

PostPosted: Tue Jan 18, 2022 2:06    Post subject: Re: For a Buffalo Buffalo WZR-HP-G300 running v3.0 (build 44 Reply with quote
feichter wrote:
* * * * * root /bin/sh /jffs/www/send.sh

^ This ^ works for me. Thanks. So so many attempts.
Q: Why is it so difficult?!!? A: IMHO: Very few log details. Frustrating

_________________
Current: Netgear R9000 DD-WRT v3.0-r55460 std (03/25/24)
Retired: Linksys WRT32X r39296, TP-Link Archer C7 v2, LinkSys WRT54G v5
eibgrad
DD-WRT Guru


Joined: 18 Sep 2010
Posts: 9157

PostPosted: Tue Jan 18, 2022 3:03    Post subject: Re: For a Buffalo Buffalo WZR-HP-G300 running v3.0 (build 44 Reply with quote
MesMurized wrote:
feichter wrote:
* * * * * root /bin/sh /jffs/www/send.sh

^ This ^ works for me. Thanks. So so many attempts.
Q: Why is it so difficult?!!? A: IMHO: Very few log details. Frustrating


You don't need the /bin/sh if you have a shebang at the top of your script.

Code:
#!/bin/sh


Also, make sure the script is marked executable.

Code:
chmod +x /path/filename


In my experience, users often have trouble because they've failed to do the above. IOW, it's NOT the scheduler (cron) that's the problem, but the script itself. So they end up having to call the interpreter directly and pass the script as an argument. But that shouldn't be necessary as long as you do the above steps when creating your scripts.

_________________
ddwrt-ovpn-split-basic.sh (UPDATED!) * ddwrt-ovpn-split-advanced.sh (UPDATED!) * ddwrt-ovpn-client-killswitch.sh * ddwrt-ovpn-client-watchdog.sh * ddwrt-ovpn-remote-access.sh * ddwrt-ovpn-client-backup.sh * ddwrt-mount-usb-drives.sh * ddwrt-blacklist-domains.sh * ddwrt-wol-port-forward.sh * ddwrt-dns-monitor.sh (NEW!)
MesMurized
DD-WRT User


Joined: 08 Aug 2017
Posts: 84

PostPosted: Tue Jan 18, 2022 3:14    Post subject: Reply with quote
Thanks... but I'm special Ugh!!! -sarcastic-

Did both, checked, then double/triple checked.

Also ... I can not execute the script (cmd, ./cmd, /xxx/cmd). Must be preceded by sh.

Hmmm.. wonder if my remote ssh connection (using Juice) is to blame. I'm going to try with telnet.

_________________
Current: Netgear R9000 DD-WRT v3.0-r55460 std (03/25/24)
Retired: Linksys WRT32X r39296, TP-Link Archer C7 v2, LinkSys WRT54G v5
eibgrad
DD-WRT Guru


Joined: 18 Sep 2010
Posts: 9157

PostPosted: Tue Jan 18, 2022 3:23    Post subject: Reply with quote
MesMurized wrote:
Thanks... but I'm special Ugh!!! -sarcastic-

Did both, checked, then double/triple checked.

Also ... I can not execute the script (cmd, ./cmd, /xxx/cmd). Must be preceded by sh.

Hmmm.. wonder if my remote ssh connection (using Juice) is to blame. I'm going to try with telnet.


FWIW, look at the script ddwrt-blacklist-domains.sh in my signature. Notice the shebang at the top. And the instruction #6 on how to add it to the scheduler. I have hundreds of users doing this every day. I'm running it myself right now, on the scheduler.

Something has to be wrong with your script, esp. if you can't even execute it from the command line.

P.S. If you want, you can send me a PM w/ the script and I'll take a look at it. If it's big, perhaps post it to PasteBin first, then provide the link.

_________________
ddwrt-ovpn-split-basic.sh (UPDATED!) * ddwrt-ovpn-split-advanced.sh (UPDATED!) * ddwrt-ovpn-client-killswitch.sh * ddwrt-ovpn-client-watchdog.sh * ddwrt-ovpn-remote-access.sh * ddwrt-ovpn-client-backup.sh * ddwrt-mount-usb-drives.sh * ddwrt-blacklist-domains.sh * ddwrt-wol-port-forward.sh * ddwrt-dns-monitor.sh (NEW!)
MesMurized
DD-WRT User


Joined: 08 Aug 2017
Posts: 84

PostPosted: Tue Jan 18, 2022 3:31    Post subject: Reply with quote
Oh sh......

That's why it's called shebang (haha). Had a she but missing the bang !. Hate getting old. Forgetting more than I learn. Can't see the rest.

Thanks a bunch

_________________
Current: Netgear R9000 DD-WRT v3.0-r55460 std (03/25/24)
Retired: Linksys WRT32X r39296, TP-Link Archer C7 v2, LinkSys WRT54G v5
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum