0

I have been running a python script as a cron job to read data from a serial port via a raspberry pi. 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.

Unfortunately, I did not redirect output from the python script in the crontab configuration. 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 enter image description here

It is hard for me to rerun my experiment and the data lost would be a blow to my research.

Cactus
  • 864
  • 1
  • 17
  • 44
  • Try looking at this post. You want to read from sys.stdout and print it to a file. https://stackoverflow.com/questions/2804543/read-subprocess-stdout-line-by-line – ericl16384 Nov 25 '20 at 00:12
  • @ericl16384 This shows a solution by changing the python code. Unfortunately my python code has already been executed and I need to obtain the data printed in the past. How would this help? – Cactus Nov 25 '20 at 00:20
  • I'm not sure it is possible, but you can: 1. Try copying it and pasting it to a file - Try using CTRL-A, CTRL-C, and to paste it, CTRL-V. - Try selecting it manually and then copy-pasting. 2. Take a lot of screenshots - You can either do this by hand, or write a script that takes screenshots and scrolls down – ericl16384 Nov 25 '20 at 01:50
  • @ericl16384 I am not sure I understand. The solution you linked to starts a new subprocess, right? How would this help with getting output from a script that has already run in the past? – Cactus Nov 25 '20 at 03:50
  • I am not sure. I am saying, while you try to figure out a solution, you may want to archive the results. If you took a lot of screenshots at regular intervals, you could put them in a file, and then "scroll" down through them. It is not easy recovering text from screenshots, but maybe screenshots is better than nothing, right? https://datatofish.com/screenshot-python/ ``` import pyautogui myScreenshot = pyautogui.screenshot() myScreenshot.save(r'Path to save screenshot\file name.png') ``` Then just loop and have it use the scroll key to scroll down. I have never used it though... – ericl16384 Nov 25 '20 at 16:25
  • Thanks for helping, but I think the screenshot solution will not work, there was no output to the screen since the script was run in the background as a cron job. – Cactus Nov 25 '20 at 16:30
  • Okay. I think I have no more solutions. I will leave my "code" up in case it helps, though. – ericl16384 Nov 25 '20 at 16:38
  • Related: https://stackoverflow.com/q/28067714 – AMC Nov 26 '20 at 21:25

1 Answers1

0

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. 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

ericl16384
  • 326
  • 3
  • 12