0
我有一个bash脚本,在每次系统启动时运行python脚本。Python脚本从Bash脚本运行不记录
该python脚本的一部分应该记录到日志文件(主要用于调试目的)。脚本运行良好,无论我手动运行它还是通过bash脚本。
问题是,当我运行它通过bash脚本时,Python脚本不会创建日志文件,也不会记录脚本中的任何调试LOGGING命令。
我假设这是目录中的权限问题。
我打电话从/etc/rc.local中
sudo /home/user/python_scripts/go.sh &
这里我的剧本是我的bash脚本(go.sh)蟒蛇行..
#!/bin/sh
python /home/user/python_scripts/go.py
里面的我Python代码我使用以下(这时候我手动运行记录放置在python_scripts目录中的日志文件:
import logging
daily_log = 'log-' + str(time.strftime("%m-%d-%y")) + '.log'
logging.basicConfig(format='%(asctime)s (%(levelname)s) - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', filename=daily_log,level=logging.DEBUG)
logging.debug(' Debug Message - Error 1241')
发布您写入文件的部分。 – njzk2
'bash'脚本如何运行? Python脚本是否写入特定的文件,或仅写入标准错误和/或输出(它是从'bash'脚本继承的,可能与手动运行Python时不同)? – chepner
更新了更多的信息... – user2451775