简体   繁体   English

从通过树莓上的 cron 运行的 python 脚本恢复打印输出

[英]Recover print output from python script run via cron on raspberry

I have been running a python script as a cron job to read data from a serial port via a raspberry pi.我一直在运行 python 脚本作为 cron 作业,通过树莓派从串行端口读取数据。 The data was supposed to be stored in a database but this did unfortunately not happen due to a bug in my code.数据应该存储在数据库中,但不幸的是由于我的代码中的错误而没有发生。 However, I did have a print statement of the read-out data in my python code.但是,我的 python 代码中确实有读取数据的打印语句。

Unfortunately, I did not redirect output from the python script in the crontab configuration.不幸的是,我没有在 crontab 配置中重定向 python 脚本的输出。 Is there any other default place where this output would be logged?是否有任何其他默认位置将记录此输出? Until now the the logging for /etc/rsyslog.conf for *cron was commented out but there is a catch-all line that was active and seems to include cron jobs, however I could not find anything in the /var/log/messages output到目前为止,*cron 的/etc/rsyslog.conf的日志记录已被注释掉,但是有一个包罗万象的行处于活动状态并且似乎包含 cron 作业,但是我在/var/log/messages找不到任何内容输出在此处输入图片说明

It is hard for me to rerun my experiment and the data lost would be a blow to my research.我很难重新运行我的实验,丢失的数据将对我的研究造成打击。

It did not format in the comments so here is some code.它没有在注释中格式化,所以这里有一些代码。 I have not run it, because I do not have pyautogui , but I hope it will help you archive screenshots of your code.我没有运行它,因为我没有pyautogui ,但我希望它可以帮助您存档代码的屏幕截图。 Test this before you rely on it.在你依赖它之前测试它。 :

import pyautogui

saveDir = r"PUT PATH HERE THAT ENDS WITH BACKSLASH --> C:PATH\"
scrollSpeed = 10  # Change this for different scrolling speed
count = 10**2 # Change for different amount of screenshots

for i in range(count):
   myScreenshot = pyautogui.screenshot()
   myScreenshot.save(f"{saveDir}screenshot{i}.png")

   pyautogui.scroll(scrollSpeed*-1)

Sources:资料来源:

https://datatofish.com/screenshot-python/ https://pyautogui.readthedocs.io/en/latest/mouse.html https://datatofish.com/screenshot-python/ https://pyautogui.readthedocs.io/en/latest/mouse.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM