Python: file works on command line but not using crontab

So, I have a file that looks like this:

#!/usr/bin/python
import MySQLdb
import subprocess
from subprocess import call
import re

conx = MySQLdb.connect (user = 'root', passwd = '******', db = 'vaxijen_antigens')
cursor = conx.cursor()
cursor.execute('select * from sequence')
row = cursor.fetchall()

f = open('/home/rv/ncbi-blast-2.2.23+/db/vdatabase.fasta', 'w')

for i in row:
    f.write('>'+i[0].strip()+'\n')
    s = re.sub(r'[^\w]','',str(i[1]))
    s = ''.join(s)
    for k in range(0, len(s), 60):
        f.write('%s\n' % (s[k:k+60]))
    f.write('\n')

f.close()

subprocess.call(['formatdb', '-p', 'T', '-i', r'/home/rv/ncbi-blast-2.2.23+/db/vdatabase.fasta'])

The file does not start from the command line, but when I try to start it using crontab, I get this error:

  File "/home/rv/ncbi-blast-2.2.23+/db/formatdb.py", line 29, in <module>
    subprocess.call(['formatdb', '-p', 'T', '-i',
r'/home/rv/ncbi-blast-2.2.23+/db/vdatabase.fasta'])
OSError: [Errno 2] No such file or directory

I do not understand, the file exists in this directory, I am twice and the triple is marked. I tried converting the file path to the raw string, so the lowercase "r" is in front of the path, but that also did not.

+3
source share
2 answers

I suspect he is complaining about the path to "formatdb" in your subprocess call. Try changing this to the full path:

subprocess.call(['/home/path/formatdb', ...])
+5
source

cron PATH. PATH crontab, Python.

+3

Source: https://habr.com/ru/post/1759185/


All Articles