Why does my cronjob not send the email from my script? [closed]

2024/9/22 7:41:34

Crontab script running from sh-3.2 (logged in as root) is:

* * * * * python /Users/tony/Documents/Python_Projects/Stock_Earnings_5.py #send an email every minute

Stock_Earnings_5 sends an email based on the logic.

Currently Stock_Earnings_5 works independently and sends out the email when manually running it from shell sh-3.2 (logged in as root).

crontab also works for "hello world" to terminal.

So in summary, crontab works for hello world program to terminal, and Stock_Earnings_5 works if called independently of crontab, but when crontab calls Stock_Earnings_5 it doesn't send email.

Answer

To properly post my comment above:

Keep in mind that the environment in which cron runs has different (minimal) variables that your user environment. Therefore, it might be (and usually is) necessary to provide the explicit path to your python executable.

The path to your default python executable can be found using the which python command.

Example:

$ which python
/home/username/anaconda3/bin/python

Then, in cron use:

* * * * * /home/username/anaconda3/bin/python /full/path/to/myscript.py
https://en.xdnf.cn/q/119610.html

Related Q&A

How to delete unsaved tkinker label?

I made this program where I am putting labels on a grid without saving them in a variable. I do this because then I can for loop through a list of classes and get the data from each class in and add th…

Adjust every other row of a data frame

I would like to change every second row of my data frame.I have a df like this:Node | Feature | Indicator | Value | Class | Direction -------------------------------------------------------- 1 | …

Why is the list index out of range?

Im new at programing and Im trying to check a piece of code that keeps giving me this error: t[i] = t[i - 1] + dt IndexError: list index out of rangeThe code is the following: dt = 0.001t = [0] for i i…

Stopping a while loop mid-way - Python

What is the best way to stop a while loop in Python mid-way through the statement? Im aware of break but I thought using this would be bad practice.For example, in this code below, I only want the pro…

Click on element in dropdown with Selenium and Python

With Selenium and Chrome webdriver on MacOS need to click dropdown element. But always have an error that cant find. Have this html code on a page where it located:<select id="periodoExtrato&qu…

Send cv2 video stream for face recognition

Im struggling with a problem to send a cv2 videostream (webcam) to a server (which shall be used later for face recognition). I keep getting the following error for the server: Traceback (most recent c…

Generate all possible lists from the sublist in python [duplicate]

This question already has answers here:How to get the Cartesian product of multiple lists(20 answers)Closed 7 years ago.Suppose I have list [[a, b, c], [d, e], [1, 2]]I want to generate list where on t…

Time/frequency color map in python

Is there in native Python 3.X library or in scipy/numpy/matplolib libraries a function or their short set which could help me to draw a plot similar to this one(?):What would be an efficient way to ac…

ImageMagick is splitting the NASAs [.IMG] file by a black line upon converting to JPG

I have some raw .IMG format files which Im converting to .jpg using ImageMagick to apply a CNN Classifier. The converted images, however have a black vertical line splitting the image into two. The par…

CV2 - rectangular detecting issue

Im trying to implement an OMR using pythons CV2. As part of the code I need to find the corners of the choices box (rectangulars) however I ran into difficulty causes by the grade sheet template. In th…