Python/Python

[Python] ^M 제거

S0PH1A 2018. 1. 19. 20:45
반응형
crontab으로 python 파일 실행시 아래와 같은 에러를 띄울 경우
/usr/bin/env: python^M: No such file or directory

문제 원인 : 
     VIM에서 (ENTER) 를 인식하지 못해 ^M ( ctrl + v + m )으로 됨.
[root@aaa test]# cat -v test.py | head
#!/usr/bin/env python^M
# -*- coding: utf-8 -*-^M
^M
from datetime import *^M
import server_connect^M
^M
import logging.handlers^M
#  logging.basicConfig(filename='./test.log', level=logging.DEBUG)^M
^M

해결 방법 :
     1) ^M 제거
       이때, 변경 전 파일명과 변경 후 파일명은 달라야 한다!  ★
 >> tr -d '\r' < [변경 전 파일명] > [변경 후 파일명]

ex) 
 >> tr -d '\r' < test.py > test.py

     

     


반응형