Hello. I installed, via python3, an application called Subliminal and another called Podfox, to download subtitles and podcasts, respectively. I need these applications to run automatically, at specific times. I edited Crontab by placing the following lines:
0 8 * * * /usr/local/AppCentral/python3/bin/subliminal --opensubtitles USER PASS download -l en-BR /volume1/TV_Shows
0 14 * * 6 /usr/local/AppCentral/python3/bin/podfox update && /usr/local/AppCentral/python3/bin/podfox download
However, none of the applications are working. When I run them through the terminal, they work, by scheduling Crontab, no. What is wrong? Is there any other way to schedule these applications to run?
ps: I don't have another user besides the administrator on the NAS.
Crontab not working
-
- Posts: 76
- youtube meble na wymiar Warszawa
- Joined: Wed Feb 05, 2020 10:49 am
- orion
- Posts: 3485
- Joined: Wed May 29, 2013 11:09 am
Re: Crontab not working
Try to output logs to a file to know what's wrong... ex: your command >> /home/test.log 2>&1
- father.mande
- Posts: 1817
- Joined: Sat Sep 12, 2015 2:55 am
- Location: La Rochelle (France)
Re: Crontab not working
Hi,
Due to the fact that crond is started by root at init phase ... NOTHING (in fact just a small things) is available in the shell environment when you start it ...
ex. the shebang is not all the time used ...
also it's NOT running in a terminal.
SO be sure :
... to use full PATH in all command in your script
... to don't start script directly but using for python as an example corresponding to your need path/to/python path/to/python/script [args] or python3
... eventually start you Python script IN a shell (so cron call the shell)
... last for Python some function (but perhaps not your case) require a true terminal ttyxxx in this case, start your script after using pty.spawn for ex.
hereafter a short and dirty example (but working, I use it) add_pty.py
usage is add_pty.py [cmd (bash script here) to start and arguments] ... bash can be replaced by any script engine (python, perl, etc.)
Philippe.
NB log as explain by "Orion" ...
Due to the fact that crond is started by root at init phase ... NOTHING (in fact just a small things) is available in the shell environment when you start it ...
ex. the shebang is not all the time used ...
also it's NOT running in a terminal.
SO be sure :
... to use full PATH in all command in your script
... to don't start script directly but using for python as an example corresponding to your need path/to/python path/to/python/script [args] or python3
... eventually start you Python script IN a shell (so cron call the shell)
... last for Python some function (but perhaps not your case) require a true terminal ttyxxx in this case, start your script after using pty.spawn for ex.
hereafter a short and dirty example (but working, I use it) add_pty.py
Code: Select all
#!/usr/bin/python3
import pty
import sys
# print ('Argument List:', str(sys.argv))
cmd = str(sys.argv[1])
# print ('/bin/bash', '-c ', cmd)
pty.spawn(['/bin/bash', '-c', cmd ])
Philippe.
NB log as explain by "Orion" ...
AS6602T / AS5202T /AS5002T / AS1002T / FS6706T
-
- Posts: 76
- Joined: Wed Feb 05, 2020 10:49 am
Re: Crontab not working
I put the following line in Crontab:father.mande wrote:Hi,
Due to the fact that crond is started by root at init phase ... NOTHING (in fact just a small things) is available in the shell environment when you start it ...
ex. the shebang is not all the time used ...
also it's NOT running in a terminal.
SO be sure :
... to use full PATH in all command in your script
... to don't start script directly but using for python as an example corresponding to your need path/to/python path/to/python/script [args] or python3
... eventually start you Python script IN a shell (so cron call the shell)
... last for Python some function (but perhaps not your case) require a true terminal ttyxxx in this case, start your script after using pty.spawn for ex.
hereafter a short and dirty example (but working, I use it) add_pty.pyusage is add_pty.py [cmd (bash script here) to start and arguments] ... bash can be replaced by any script engine (python, perl, etc.)Code: Select all
#!/usr/bin/python3 import pty import sys # print ('Argument List:', str(sys.argv)) cmd = str(sys.argv[1]) # print ('/bin/bash', '-c ', cmd) pty.spawn(['/bin/bash', '-c', cmd ])
Philippe.
NB log as explain by "Orion" ...
30 19 * * * /usr/local/AppCentral/python3/bin/python3 /usr/local/AppCentral/python3/bin/podfox update >> /volume2/Temp/podofx_log 2> & 1
The saved log has the following content:
Traceback (most recent call last):
File "/usr/local/AppCentral/python3/bin/podfox", line 11, in <module>
sys.exit (main ())
File "/usr/local/AppCentral/python3/lib/python3.7/site-packages/podfox/__init__.py", line 288, in main
with open (configfile) as conf_file:
FileNotFoundError: [Errno 2] No such file or directory: '/root/.podfox.json'
So, what's wrong?
-
- Posts: 76
- Joined: Wed Feb 05, 2020 10:49 am
Re: Crontab not working
On the Subliminal documentation page there is an instruction to schedule with Cron. There they say to add this line:
0 1 * * * user /path/to/subliminal -m -l en -l fr -w 1 -a 1w -q /path/to/videos/
I added, without the user option (I don't know what it is, since there is only the admin user on my NAS) and it didn't work either.
0 1 * * * user /path/to/subliminal -m -l en -l fr -w 1 -a 1w -q /path/to/videos/
I added, without the user option (I don't know what it is, since there is only the admin user on my NAS) and it didn't work either.
- father.mande
- Posts: 1817
- Joined: Sat Sep 12, 2015 2:55 am
- Location: La Rochelle (France)
Re: Crontab not working
Hi,
User option don't exist in crontab BUT each user can have a specific and private crontab
... so be sure that your command is able to run as admin or root (user root also exist and run the system crontab)
And, again ... don't use directly a script (python) in crontab ... the best is (also for log) to start a shell script in the shell add all environment variable needed and run your command in this bash script using also some log information and output.
Philippe.
User option don't exist in crontab BUT each user can have a specific and private crontab
... so be sure that your command is able to run as admin or root (user root also exist and run the system crontab)
And, again ... don't use directly a script (python) in crontab ... the best is (also for log) to start a shell script in the shell add all environment variable needed and run your command in this bash script using also some log information and output.
Philippe.
AS6602T / AS5202T /AS5002T / AS1002T / FS6706T
-
- Posts: 76
- Joined: Wed Feb 05, 2020 10:49 am
Re: Crontab not working
I'm still unsure how to do this, since my NAS is an AS1002T and it seems to be limited in terms of commands and tools. What would the procedure be like to run the python script indirectly? My python 3 is in /usr/local/bin, as well as podfox and subliminal. I would appreciate it if you gave me the way because I am not very familiar with Linux.father.mande wrote:Hi,
User option don't exist in crontab BUT each user can have a specific and private crontab
... so be sure that your command is able to run as admin or root (user root also exist and run the system crontab)
And, again ... don't use directly a script (python) in crontab ... the best is (also for log) to start a shell script in the shell add all environment variable needed and run your command in this bash script using also some log information and output.
Philippe.
- father.mande
- Posts: 1817
- Joined: Sat Sep 12, 2015 2:55 am
- Location: La Rochelle (France)
Re: Crontab not working
Hi,
Hum! I have no time to debug a tools ... that I don't used ...
my short suggestion is :
... verify that shebang ( first line (starting with #! )of script are pointing to the good python3 ... on other Linux it's generally /usr/bin/python3 when in A.D.M it's /usr/local/bin/python3
... change line in crontab by (and test change hours by minutes (5 for ex.) to see if it works ... change 0 1 * * * by 5 * * * *) or any value corresponding to a valuable delay
0 1 * * * /usr/local/bin/python3 /path/to/subliminal -m -l en -l fr -w 1 -a 1w -q /path/to/videos/
Last you must have some knowledge in Linux to write a short script like this
replace in crontab the call to python script by this shell script (put it executable) and redirect output to a file (in /tmp for ex.) to have idea of error or output done.
Philippe.
NB if you need full GNU tools and not limited ones provide by Asustor through busybox ... use Entware APKG and its +2500 packages
Hum! I have no time to debug a tools ... that I don't used ...
my short suggestion is :
... verify that shebang ( first line (starting with #! )of script are pointing to the good python3 ... on other Linux it's generally /usr/bin/python3 when in A.D.M it's /usr/local/bin/python3
... change line in crontab by (and test change hours by minutes (5 for ex.) to see if it works ... change 0 1 * * * by 5 * * * *) or any value corresponding to a valuable delay
0 1 * * * /usr/local/bin/python3 /path/to/subliminal -m -l en -l fr -w 1 -a 1w -q /path/to/videos/
Last you must have some knowledge in Linux to write a short script like this
Code: Select all
#!/bin/sh
export PATH=/opt/bin:/opt/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/builtin/sbin:/usr/builtin/bin:/usr/local/sbin:/usr/local/bin
/usr/local/bin/python3 /path/to/subliminal -m -l en -l fr -w 1 -a 1w -q /path/to/videos/
Philippe.
NB if you need full GNU tools and not limited ones provide by Asustor through busybox ... use Entware APKG and its +2500 packages
AS6602T / AS5202T /AS5002T / AS1002T / FS6706T