0

I'm starting a script every day with a cronjob:

0 1 * * * /bin/bash /home/performanceRatio.sh

Script:

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

python3 /home/get_weather_data_crn.py && 
python3 /home/pv.py

The script is running but writing just NULL to the mysql database:

| 2021-02-03 13:00:00 |    48.17 |     11.14 |     NULL |    NULL |     NULL |     NULL | 20          | 1         | CRN    |
| 2021-02-03 14:00:00 |    48.17 |     11.14 |     NULL |    NULL |     NULL |     NULL | 20          | 1         | CRN    |
| 2021-02-03 15:00:00 |    48.17 |     11.14 |     NULL |    NULL |     NULL |     NULL | 20          | 1         | CRN    |
| 2021-02-03 16:00:00 |    48.17 |     11.14 |     NULL |    NULL |     NULL |     NULL | 20          | 1         | CRN

It is getting data from CAMS (a weather service). When starting the script manually it works as it should. The database connection seems to work, it's just not writing the weather values as expected when run with Cron. The other values are written.

Using: Ubuntu 20.04

It's written to the db with:

engine = create_engine('mysql+pymysql://{}:{}@{}/{}'.format(user, passwd, host, database))
df.to_sql(con=engine, name=name, if_exists='append', index = True, chunksize=1000)
8
  • Any question should always include the version of Ubuntu you are using. Please edit the question or add a flag. What version is it? It is possible the version affects the answer.
    – David
    Feb 5, 2021 at 8:15
  • It may be related to the user that is running the script when it's triggered by crontab. This may help stackoverflow.com/questions/8475694/…
    – Katu
    Feb 5, 2021 at 8:27
  • @David I wrote the ubuntu Version. It's 20.04
    – why me
    Feb 5, 2021 at 8:28
  • @Katu The script is run by the root user I guess, I'm editing the crontab -e file within the root shell (sudo -s) and didn't specify anything else. How would I check this?
    – why me
    Feb 5, 2021 at 8:30
  • Can you try this using ./etc/crontab and the user you use? Next: please do not put scripts in /home/, There should only be directories there than point to USERS. Lets assume you could delete a user pv.py your script is gone.
    – Rinzwind
    Feb 5, 2021 at 8:30

1 Answer 1

0

It seemed to be a problem with my paths. I edited crontab -e like this and it worked on a every minute schedule (So it will at 1am too, I guess):

0 1 * * * cd /home && /bin/bash /home/performanceRatio.sh

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .