Crontab不会运行python脚本
发布于 2021-01-29 16:53:31
当我从命令行执行python脚本时,我没有像这样的问题:
[rv @ med240-183 db] $ python formatdb.py
[rv @ med240-183 db] $
当我尝试使用crontab在每个午夜运行脚本时,出现了一系列错误:
import: unable to open X server `' @ import.c/ImportImageCommand/367.
/home/rv/ncbi-blast-2.2.23+/db/formatdb.py: line 2: from: command not found
/home/rv/ncbi-blast-2.2.23+/db/formatdb.py: line 3: from: command not found
import: unable to open X server `' @ import.c/ImportImageCommand/367.
/home/rv/ncbi-blast-2.2.23+/db/formatdb.py: line 6: syntax error near
unexpected token `('
/home/rv/ncbi-blast-2.2.23+/db/formatdb.py: line 6: `conx = MySQLdb.connect
(user = 'root', passwd = '******', db = 'vaxijen_antigens')'
我的脚本目录如下:
/home/rv/ncbi-blast-2.2.23+/db/
Crontab看起来像:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/bin/python/:/home/rv/ncbi-blast-2.2.23+/database_backup:/home/rv/ncbi-blast-2.2.23+/db/
MAILTO="******"
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed
0 0 * * * root /home/rv/ncbi-blast-2.2.23+/database_backup/backup.py
0 0 * * * root /home/rv/ncbi-blast-2.2.23+/db/formatdb.py
和我的python脚本看起来像:
import MySQLdb
from subprocess import call
from subprocess import Popen
import re
conx = MySQLdb.connect (user = 'root', passwd = '******', db = 'vaxijen_antigens')
cursor = conx.cursor()
cursor.execute('select * from sequence')
row = cursor.fetchall()
f = open('vdatabase.fasta', 'w')
for i in row:
f.write('>'+i[0].strip()+'\n')
#f.write(i[1].strip().replace(' ','')+'\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
Popen(["formatdb", "-p", "T", "-i", "vdatabase.fasta"]).wait()
关注者
0
被浏览
75
1 个回答
推荐阅读
-
尝试从ubuntu crontab运行python脚本
2021-01-29 关注 0 浏览61 1答案
-
Python脚本未在调用pysaunter的crontab中运行
2021-01-29 关注 0 浏览83 1答案
-
使用crontab运行脚本时无法导入Python MySQL模块
2021-01-29 关注 0 浏览77 1答案
-
通过crontab执行Python脚本
2021-02-02 关注 0 浏览115 1答案
-
Crontab没有执行Python脚本?
2021-01-29 关注 0 浏览80 1答案
-
Crontab无法执行Python脚本
2021-01-29 关注 0 浏览143 1答案
-
RPi python脚本无法从以下位置运行:/etc/rc.local、crontab、systemd
2021-01-29 关注 0 浏览90 1答案
-
用crontab运行selenium(python)
2021-02-01 关注 0 浏览78 1答案
-
如何确定是否从crontab执行了python脚本?
2021-01-29 关注 0 浏览70 1答案
-
如何通过脚本创建 crontab
2022-07-28 关注 0 浏览9 1答案