I have a daily batch run in django with cron.
# crontab -e
All but the bottom of these batches seem to work correctly.
0 0 * * * root /root/certbot.sh
0 18 * * * root /var/www/html/venv/bin/python /var/www/html/portfolio/mysite/manage.py daily_import_from_vietkabu
5 18 * * * root /var/www/html/venv/bin/python /var/www/html/portfolio/mysite/manage.py daily_import_from_sbi
6 18 * * * root /var/www/html/venv/bin/python /var/www/html/portfolio/mysite/manage.py daily_import_from_bloomberg
15 18 * * * root /var/www/html/venv/bin/python /var/www/html/portfolio/mysite/manage.py daily_industry_chart_and_uptrends
20 18 * * * root /var/www/html/venv/bin/python /var/www/html/portfolio/mysite/manage.py daily_industry_stacked_bar_chart
30 18 * * * /root/collectstatic.sh << this!!
The shell script that is triggered has the following written
(/root/collectstatic.sh)
# /bin/sh
cd /root
source /var/www/html/venv/bin/activate
python3 /var/www/html/portfolio/mysite/manage.py collectstatic --noinput
The command at the bottom is the standard django command to copy static files to a fixed location. These batches with cron, as far as I remember, came straight from the migration from "CentOS" and may not work well with current ubuntu with cron.
Has anyone ever run django's collectstatic with ubuntu's cron?
thanks.
Related
I have a crontab settings as follows:
sudo crontab -l -u bheng
Contents:
#field allowed values
# ----- --------------
# minute 0-59
# hour 0-23
# day of month 1-31
# month 1-12 (or names, see below)
# day of week 0-7 (0 or 7 is Sun, or use names)
#
# m h dom mon dow command
MAILTO="bheng#outlook.com"
#Daily
01 22 * * * php /home/mysite.com/artisan products:exportdiff --interval="yesterday"
16 22 * * * php /home/mysite.com/artisan images:exportdiff --interval="yesterday"
31 22 * * * php /home/mysite.com/artisan publications:exportdiff --interval="yesterday"
#Weekly
1 23 * * 7 php /home/mysite.com/artisan publications:exportdiff --interval="last sunday"
16 23 * * 7 php /home/mysite.com/artisan images:exportdiff --interval="last sunday"
31 23 * * 7 php /home/mysite.com/artisan products:exportdiff --interval="last sunday"
As you can see, it suppose to be kicking at 10 and 11 PM at night.
But instead, I got 3 emails at 5 PM yesterday at 5:01 PM, 5:16 PM, 5:31 PM.
I thought it was the time wrong the in system or VM so I checked it I saw UTC time.
Then, I update it by running sudo dpkg-reconfigure tzdata and set it to US Eastern time.
Now, when I ran date command I got Ex.Thu Dec 15 07:56:27 EST 2016 correctly as US EST time.
Is there some service that I need to restart?
Or is this something other crontab settings that might have overwrite my current settings ?
I believe you have to restart cron after making time / time zone related changes.
Depending on your version of cron, you might be able to restart it with sudo service cron restart.
I got this crontab code to run a script on crontab every 15 minutes from 9 to 18 all days except weekends. However I would like to start fro 9:30 instead of 9. Is it there a way to do it?
*/15 9-18 * * 1-5
Using 30/15 in the minute area should work just fine:
30/15 9-18 * * 1-5
This will instruct crontab to run your script: “At every 15th minute from 30 through 59 past every hour from 9 through 18 on every day-of-week from Monday through Friday.”
I finally did this, and it works
30 9 * * 1-5
45 9 * * 1-5
*/15 10-18 * * 1-5
However, it needs three crontab entries.
I am running crontab -l to view the crons on a RHEL server(v5.10) and getting the below error:
crontab: error while loading shared libraries: libaudit.so.1: cannot open shared object file: No such file or directory
I am running the command via root user. If I go to /etc and open the crontab file using the cat command I am getting the following output:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
i have a problem with crontab not running a script of mine at all. i have simplified the script down to a single line but it still won't run:
$ cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
*/1 * * * * root /usr/share/test/script.sh
# don't forget the newline at the end (https://askubuntu.com/a/23337/12057):
$ cat /usr/share/test/script.sh
#!/bin/bash
echo "got here" > /tmp/test.txt
$ ls -l /usr/share/test/script.sh
-rwxr-xr-x 1 root root 951 May 8 08:59 /usr/share/test/script.sh
$ uname -a
Linux mypcname 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux
$ ps aux | grep cron
root 1111 0.0 0.0 22222 3333 ? Ss 08:27 0:00 /usr/sbin/cron
me 4444 0.0 0.0 5555 666 pts/0 S+ 09:06 0:00 grep --color=auto cron
as you can see the crontab should run script.sh once a minute and write to file /tmp/test.txt, however this file never appears. i have been reading through these possible reasons for cron not running, but so far none of them are applicable. i thought a fresh set of eyes might shed some light.
Every minute is
* * * * *
not
*/1 * * * *
Related question: Using crontab to execute script every minute and another every 24 hours
/var/log/syslog gave the clue to the answer:
May 8 08:50:01 mypcname /usr/sbin/cron[2222]: (*system*) WRONG FILE OWNER (/etc/crontab)
May 8 08:51:01 mypcname /usr/sbin/cron[2222]: (*system*) WRONG FILE OWNER (/etc/crontab)
$ ls -l /etc/crontab
lrwxrwxrwx 1 root root 24 Oct 12 2013 /etc/crontab -> /home/me/.crontab
$ ls -l ~/.crontab
-rw-r--r-- 1 root root 24 Oct 12 2013 /home/me/.crontab
i remember i did this when i installed the debian os since everything in my home dir is checked out from a subversion repository. i fixed up the issue like so:
$ sudo cp ~/.crontab /etc/crontab
and now it all works fine :)
I have a crontab in fedora 17 with command
13 10 * * * /home/pk1/Templates/dump.sh
In dump.sh
#!/bin/sh
mysqldump --host=localhost --user=root --password=toor mba_new | gzip > /home/pk1/Templates/`date +"webt-backup_%m-%d-%y"`.gz
In log file have an error
Mar 25 10:13:01 area7 crond[31770]: (*system*) RELOAD (/etc/crontab)
Mar 25 10:13:01 area7 crond[31770]: (CRON) bad command (/etc/crontab)
if I run through terminal
sh dump.sh
everything is ok
Why my dump.sh not work through crontab? Thanks
Your crontab needs a username Please specify it as
13 10 * * * pk1 /home/pk1/Templates/dump.sh