0

I have a script running via crontab

It runs perfectly till a certain time and print statements show up in the log file. After this particular time, the log file doesn't have any more entries.

I checked whether the script is still running:

ps aux | grep script_name

Shows in the results:

>ubuntu   19748  0.0  0.0   4636   820 ?        Ss   09:15   0:00 /bin/sh -c python3 /home/ubuntu/ib/op_script/process.py > /home/ubuntu/logs/process.log 2>&1
>ubuntu   19751  0.1  9.4 812908 381100 ?       Sl   09:15   0:23 python3 /home/ubuntu/ib/op_script/process.py
>ubuntu   23161  0.0  0.0  14860  1080 pts/0    S+   13:57   0:00 grep --color=auto process

I checked the free memory:

free -h

Output:

 total        used        free      shared  buff/cache   available
Mem:           3.8G        1.4G        208M         12M        2.2G        2.1G
Swap:            0B          0B          0B

I am not sure how to check what the error might be, or if the script is still doing its functions just not writing to the log file.

Note: the functions are repetitive in a while loop and have run multiple times before. I am not sure what would be the reason for no print statements coming

MattDMo
  • 100,794
  • 21
  • 241
  • 231
Sid
  • 3,749
  • 7
  • 29
  • 62
  • Run the script on its own without redirecting output and see if it dies. – MattDMo Feb 24 '23 at 19:03
  • Have you tried setting the `PYTHONUNBUFFERED` env var to turn off output buffering? See also https://stackoverflow.com/questions/107705/disable-output-buffering – Nick ODell Feb 25 '23 at 01:45

1 Answers1

0

A few steps to check:

  1. Check if there is entry in /var/log/syslog
grep CRON /var/log/syslog

This will show what commands were run by cron.

  1. Check if there is anything in mail
tail /var/mail/<the username you setup cron job>

by default cron redirect sys outputs to mail.

  1. independent cron log can be enabled by remove the comment of line #cron.* /var/log/cron.log in /etc/rsyslog.d/50-default.conf

Hopefully these information can help you locate the issue.

BookSword
  • 328
  • 1
  • 6