python - 使用 Cron 作业的 Python 脚本未将输出保存到 Google VM 实例中的文件
问题描述
我正在尝试使用 Cron 作业在我的 Google VM 实例中运行 python 脚本。
- 我的脚本应该从网站记录一些数据并将其存储在 CSV 文件中。我尝试使用通常的方式运行它
python3 kb_sc.py
,它工作得很好。
... #scrape the website
print("checkpoint")
if not (os.path.isdir(path)):
os.makedirs(path)
if not (os.path.isfile(path + file)):
data_new.to_csv(path+file, index = False)
else:
data = pd.read_csv(path+file)
data = data.append(data_new)
data.to_csv(path+file, index = False)
print("done")
- 我使用它入伍
sudo crontab -e
并输入日程安排为* * * * * cd /home/[myusername] && python3 kb_sc.py
- 我确保我的脚本可以使用
sudo chmod +x kb_sc.py
- 我确保 CRON 正在使用
sudo service cron status
- 我什至还在
> kb.log
CRON 命令的末尾添加了以* * * * * cd /home/[myusername] && python3 kb_sc.py
查看它是否打印checkpoint
和done
消息。该kb.log
文件已创建,但它是空的。
我不知道还有什么导致这个问题,更不用说解决了。
解决方案
推荐阅读
- python - 如何使用 Python 从数据框中删除“=-inf”?
- flutter - Flutter 和存储数据
- python - 是否可以在 tkinter 中有一个清晰/透明的标签?
- javascript - ES6:重新定义导出函数
- python - Numpy.around() 将 ndarray len 45 转换为 ndarray len 1
- reactjs - react导航中获取标签导航器当前活动屏幕路径
- php - 无效的对象或资源 mysqli_stmt 错误
- javascript - Firebase 在访问已删除然后重新创建的帐户的个人资料照片时返回“no-referrer-when-downgrade”
- linux - 发送 sctp 数据时 sctp_send() 失败
- jenkins-pipeline - Jenkins 扩展选择参数 groovy 脚本不起作用