Aakash Sharma Aakash Sharma -4 years ago 133
Python Question

Python script not sending database log to server from crontab

The issue is that when I execute the Python script normally from the terminal it is working fine but when the same file is being executed from the cron, there is no update at the server end.

File permissions have been set to 755. Earlier getting an error "No MTA installed, discarding output"; to solve that I use

>/dev/null 2>&1
at the end of my cron job. After that I get no error but still the issue remains the same. Also I have mentioned the environment on top of my python script.
configuration of cron is as follows:

* * * * * sudo python3 /home/pi/json_working/json_to_server_update.py >/dev/null 2>&1

Answer Source

the problem is solved now. I am using user crontab and i solved the issue by using os.path.isfile(os.path.join("path", "file name")) rather than os.path.isfile("path of file"). The latter one is actually a path and not a file so the output was always false and the sync was not made due to that. Now everything is working fine.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download