As far as I understand it .... anacron is not a daemon and is ran by cron. cron runs at boot and runs anacron. anacron checks to see if something its programmed with has missed its schedule and runs it.
Since this is the way I see it ... it would seem that you would want the daily job set in anacron. As for hourly in anacron .. I also haven't seen anything on how it can be setup so I would put the hourly backup in cron.
I know this doesn't explain it that well but ... I guess it confuses me too. I'm sure someone here can come up with a better, more satisfying answer but I figured I would generalize it.
Better approach would be to use a wrapper script, that will call the main script. This would look like this:
#!/bin/bash
# This is /home/user/bin/wrapper.sh file
pkill -f 'main_script.sh'
exec bash ./main_script.sh
Of course wrapper has to be named differently. That way, pkill
can search only for your main script. This way your main script reduces to this:
#!/bin/sh
cd /home/user/spiders/goods
PATH=$PATH:/usr/local/bin
export PATH
scrapy crawl good
Note that in my example I am using ./
because script was in my current working directory. Use full path to your script for best results
I have tested this approach with a simple main script that just runs infinite while loop and wrapper script. As you can see in screenshot, launching second instance of wrapper kills previous
Your script
This is just example. Remember that I have no access to scrapy to actually test this so adjust this as needed for your situation.
Your cron entry should look like this:
0,30 * * * * /home/us/jobs/scrapy_wrapper.sh
Contents of scrapy_wrapper.sh
#!/bin/bash
pkill -f 'run_scrapy.sh'
exec sh /home/us/jobs/run_scrapy.sh
Contents of run_scrapy.sh
#!/bin/bash
cd /home/user/spiders/goods
PATH=$PATH:/usr/local/bin
export PATH
# sleep delay now is not necessary
# but uncomment if you think it is
# sleep 2
scrapy crawl good
Best Answer
The order for Ubuntu is top-down but in parallel.
Meaning, for your example:
taskB
starts first,taskC
without waiting fortaskB
to complete,taskA
without waiting fortaskC
ortaskB
to completeUbuntu inherits this order from Debian. But in general this behavior may vary by Linux distribution/version and
cron
implementation. You should not depend on it to be the same. For example, in FreeBSD, the order is bottom-up!If the scripts depend on each other, best to call them in sequence, one from the other, or from a "master" wrapper script, which is the only one
cron
actually executes.