What's new

cron job issue on ac68u?

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

rigstars2

Occasional Visitor
I have a few cron jobs on my ac68u router running merlin.. The “watch” one below doesn’t work but the other 2 does. If I run the watch.sh script manually it works. For testing purposes, the permission is 777 and I believe */2 * * * * tells the cron to run the script every 2 minutes. Any ideas what could be wrong? I added the cron job like this -

cru a watch “*/2 * * * * /jffs/scripts/watch.sh”

# cru l
cru a lan_monitor "* * * * * /jffs/scripts/lan_monitor.sh"
cru a blocklist_update "0 0 * * FRI /jffs/scripts/blocklist_update.sh"
cru a watch "*/2 * * * * /jffs/scripts/watch.sh"
 
I have a few cron jobs on my ac68u router running merlin.. The “watch” one below doesn’t work but the other 2 does. If I run the watch.sh script manually it works. For testing purposes, the permission is 777 and I believe */2 * * * * tells the cron to run the script every 2 minutes. Any ideas what could be wrong? I added the cron job like this -

cru a watch “*/2 * * * * /jffs/scripts/watch.sh”

# cru l
cru a lan_monitor "* * * * * /jffs/scripts/lan_monitor.sh"
cru a blocklist_update "0 0 * * FRI /jffs/scripts/blocklist_update.sh"
cru a watch "*/2 * * * * /jffs/scripts/watch.sh"
cru l output is different than your post, you posted the cru a commands.
They appear to be valid but the actual cru l output is needed to troubleshoot your issue.
 
sorry about that.. here you go

* * * * * /jffs/scripts/lan_monitor.sh #lan_monitor#

0 0 * * FRI /jffs/scripts/blocklist_update.sh #blocklist_update#

*/2 * * * * /jffs/scripts/watch.sh #watch#
 
yes, i currently have that and tried #!/opt/bin/bash...
its weird how this doesn’t get called by cron but runs fine manually...


————————-
#!/bin/sh

TO=“xxxxxxxx@gmail.com"

SUBJECT=“Tampered Notification"

SIGN="[Sent from xxxxxx]”

MAIL="/opt/bin/msmtp"


found()

{

if [ $(find "/jffs/$1" -type f -mmin -2 -exec ls -1A {} \; | wc -l) -gt 0 ]; then

files="$(find "/jffs/$1" -type f -mmin -2)"

echo -e "To: ${TO}\nSubject: '$1' ${SUBJECT}\n\n$files\n\n$SIGN" | $MAIL -a gmail ${TO}

sync

fi

}


found "scripts"

found "configs"
 
The problem is your script relies on the entware version of find. The entware environment is not established by default for non-interactive sessions. So my guess is the script is running, but aborting.
 
the only thing i can think of is maybe the cron code..? is this not saying “every 2 minutes”

*/2 * * * *
 
So if you just run this command all by itself it works?
Code:
/jffs/scripts/watch.sh

Try the longhand way
0,2,4,6,8,10...etc.
 
Either rewrite the script so that is doesn't use the -type or -mmin options, or use the full pathname to entware's find command (/opt/bin/find).
 
i added logger at end of script..so cron is calling it fine and the email commands are called way before the logger line of code so shouldn’t it work regardless if its non-interactive or not?

## added this line
logger -t $(basename $0) "THIS SCRIPT WAS CALLED!"

## output on syslog
Jan 27 10:12:00 watch.sh: THIS SCRIPT WAS CALLED!
Jan 27 10:14:00 watch.sh: THIS SCRIPT WAS CALLED!
 
i added logger at end of script..so cron is calling it fine and the email commands are called way before the logger line of code so shouldn’t it work regardless if its non-interactive or not?
No. As I explained, your script is using the wrong version of the find command because the default environment variables are different.
 

Similar threads

Latest threads

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