What's new

Creating a crontab task that runs hourly - help

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

sam3

Occasional Visitor
Hi I have installed flexget on my RT-N66U using this generic openwrt guide:
http://flexget.com/wiki/InstallWizard/OpenWrt

It all runs perfectly when I run it manually but I want to set it up to run every hour using crontab. Ive read the readme file RMerlin created for crond on asuswrt:
https://github.com/RMerl/asuswrt-merlin/blob/master/README-merlin.txt
* Crond *
Crond will automatically start at boot time. You can
put your cron tasks in /var/spool/cron/crontabs/ . The file
must be named "admin" as this is the name of the system user.
Note that this location resides in RAM, so you would have to
put your cron script somewhere such as in the jffs partition,
and at boot time copy it to /var/spool/cron/crontabs/ using
an init-start user script.

A simple way to manage your cron jobs is through the
included "cru" command. Just run "cru" to see the
usage information. You can then put your "cru"
commands inside a user script to re-generate your cron jobs
at boot time.
And have come up with a script:

Create init-start file
Code:
nano -w /jffs/scripts/init-start
Command inside init-start file to copy cron job file from jffs to ram
Code:
#!/bin/sh
cp /jffs/scripts/ADMIN_USERNAME /var/spool/cron/crontabs/ADMIN_USERNAME
Save/exit nano then make init-start executable
Code:
chmod a+rx /jffs/scripts/init-start


Creating cron job file
Code:
nano -w /jffs/scripts/ADMIN_USERNAME
Command inside cron job file
Code:
@hourly /opt/bin/flexget --cron
Save exit nano

Will this work? - Im very new to linux and this is my first time deviating from a guide :eek:
Do I need to do anything to the cronjob file once its in the ram to get it to run?
 
Last edited:
Will this work? - Im very new to linux and this is my first time deviating from a guide :eek:
Do I need to do anything to the cronjob file once its in the ram to get it to run?
Hi,

Not sure if this is the way. :rolleyes:
I use the cru command to do the job. Here my services-start script from the jffs/scripts folder:
Code:
#!/bin/sh
/usr/bin/logger -t START_$(basename $0) "started [$@]"
SCRLOG=/tmp/$(basename $0).log
touch $SCRLOG
echo "START_$(basename $0) started [$@]" >> $SCRLOG
[B]/usr/sbin/cru a RestartWifi " 0 4 * * * /jffs/scripts/restart-wlan.sh"[/B] >> $SCRLOG
wait
[B]/usr/sbin/cru a LEDsoff " 0 20 * * * /jffs/scripts/ledsoff.sh"[/B] >> $SCRLOG
wait
[B]/usr/sbin/cru a LEDson " 0 8 * * * /jffs/scripts/ledson.sh"[/B] >> $SCRLOG
wait
if [ "$?" -ne 0 ]
then
echo "Error in services-start execution! Script: $0" >> $SCRLOG
#exit $?
else
echo "Services-start execution OK. Script: $0" >> $SCRLOG
#exit 0
fi
/usr/bin/logger -t STOP_$(basename $0) "return code $?"
exit $?

Of course you need to set the right cru command for your timing the command you want to execute.

With kind regards
Joe :cool:
 
Hi!

I'm trying the same thing, but it seems as if cron is not working...?!

I have this script:

/jffs/scripts/init-start

The contents is:
Code:
#!/bin/sh
/usr/sbin/cru a Flexget "*/5 * * * * /opt/local/bin/flexget -c /tmp/mnt/MK-1TB/Flexget/config.yml execute"

(I want it to run every 5 minutes now because I'm testing, I'll eventually set it to one hour interval).

When I reboot the router and check the crontab via this command:

cru l

I get this response:

Code:
admin@Router:/tmp/home/root# cru l
*/5 * * * * /opt/local/bin/flexget -c /tmp/mnt/MK-1TB/Flexget/config.yml execute #Flexget#

So it seems the crontab is set up after the reboot, but it seems like 'flexget' is not running: the flexget log doesn't show activity, and nothing seems to happen.

Did I miss something? :)
 
Hi
Its been a while since I've used Flexget - I now have a nas that handles all these operations using nzbdrone ;)

I did find some muddled notes on how I got it working:

Running Flexget via cron
nano -w /jffs/scripts/init-start

Code:
#!/bin/sh
cru a Flexget "0 * * * * flexget --cron"

where 0 * * * * was for hourly and the --cron flag was to stop flexget logs

Save exit nano
Make executable
chmod a+rx /jffs/scripts/init-start
 
Thanks! I'll give it another try... :)

I didn't know about the --cron flag, is this necessary? I'll google it... ;)

Plus: I see you didn't use the 'execute' option?
 
Last edited:
Thanks! I'll give it another try... :)

I didn't know about the --cron flag, is this necessary? I'll google it... ;)

Plus: I see you didn't use the 'execute' option?

The --cron flag just stops excessive "debug" logs when running flexget.
It stops creating huge log files and is recommended after you have tested and configured flexget properly and plan to run it automated.

Its been nearly a year since I last used flexget. I don't think the execute option was necessary when I was using it (well it wasn't included in any of the flexget setup documentation at the time ;) ).
 
The --cron flag just stops excessive "debug" logs when running flexget.
It stops creating huge log files and is recommended after you have tested and configured flexget properly and plan to run it automated.

Its been nearly a year since I last used flexget. I don't think the execute option was necessary when I was using it (well it wasn't included in any of the flexget setup documentation at the time ;) ).

Thanks, got it all working now!

By the way, I also have a NAS but I'm trying to cut down on evergy costs haha, I'm trying to replace sickbeard etc on my NAS with flexget on the router... it's kind of a hobby project ;)
 

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!

Staff online

Top