2016-07-01 8 views
0

crontab에서 python 스크립트를 실행하려고합니다.local() 회의 중 python 스크립트를 실행하지 못했습니다.

은 crontab가 호출
import sys 
import datetime 
from fabric.api import local 

ystd = datetime.date.today() - datetime.timedelta(days=1) 
c = ystd.strftime('%Y-%m-%d') 
print(c) 
print('Start to format file ...') 
...... 
print('Start to upload on HDFS ...') 
local("/home/hadoop/hadoop/bin/hadoop fs -put " + finalfile + " /user/hadoop/yunying/openapp") 
print('Start to upload on MaxCompute ...') 
...... 

, 로그 파일이 같은입니다 :

2016-07-01 
Start to format file ... 
Start to upload on HDFS ... 
[localhost] local: /home/hadoop/hadoop/bin/hadoop fs -put /data/uxin/nsq_client_active_collect/hadoop/openappfinal.log /user/hadoop/yunying/openapp 

그리고이 과정이 끝난

5 0 * * * python /home/hadoop/import_openapp.py >> /home/hadoop/openapp.out 2>&1 

파이썬 스크립트는 다음과 같은 것입니다. 찾을 수 없습니다. ps -ef|grep python

local() 회의 중에 끝나야하는 이유는 무엇입니까?

+2

cron에서 실행되는 모든 것은 아주 최소한의 환경에서만 실행되므로, PYTHONPATH를 조정할 때 의존한다면 그럴 것입니다. – Vatine

+0

쉘에서/home/hadoop/hadoop/bin/hadoop fs -put /data/uxin/nsq_client_active_collect/hadoop/openappfinal.log/user/hadoop/yunying/openapp 명령을 실행하려고 시도 했습니까? cron이 올바른 사용자의 crontab에 설정되어 있습니까? 모든 권한 문제가 있습니까? – BangTheBank

답변

0

PYTHONPATH는 CRON이 스크립트를 실행하는 데 사용하는 사용자에 관계없이 올바르게 설정되지 않았을 수 있습니다. 확인하기 위해 디버그 파일의 경로를 인쇄 :

with open('/path/to/debug_file.txt', 'wt') as f: 
    f.write(str(sys.path)) 

시도가 라인을 추가 : 지역

를 가져 오기 전에

sys.path.append("/path/to/fabric.api") 

을 당신은 동적되고있는 파일의 위치를 ​​얻을 수 있습니다

import os 
os.path.realpath(__file__) 

이렇게하면 필요한 경우 상대 경로를 사용할 수 있습니다. em

+0

'hadoop fs -put' 명령을 실행하는 동안'local()'이 아니라 JAVA_HOME이 설정되어 있지 않습니다. 고맙습니다! –

관련 문제