I am trying to cron a script I have written but I keep getting errors.
My cron looks like
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
*/2 * * * * /opt/project_1/myscript.sh >> /tmp/cron.log 2>&1
The script it runs looks like
#! /bin/bash
main_path='/opt/project_1/'
source ${main_path}venv/bin/activate
python3 ${main_path}main.py
This is the error I receive in cron.log
:
Traceback (most recent call last):
File "/opt/project_1/main.py", line 4, in <module>
from geopy.geocoders import Nominatim
ModuleNotFoundError: No module named 'geopy'
This is my pip list
:
pr0xibus@fedora:/opt/project_1$ source venv/bin/activate
(venv) pr0xibus@fedora:/opt/project_1$ pip list
Package Version
---------------------- ---------
acme 2.11.0
argcomplete 3.3.0
Beaker 1.12.1
beautifulsoup4 4.12.3
blivet 3.10.0
blivet-gui 2.5.0
boto3 1.34.128
botocore 1.34.128
Brlapi 0.8.5
bs4 0.0.2
certbot 2.11.0
certbot-apache 2.11.0
cffi 1.16.0
charset-normalizer 3.3.2
click 8.1.7
ConfigArgParse 1.7
configobj 5.0.8
cryptography 41.0.7
cupshelpers 1.0
dasbus 1.7
dbus-python 1.3.2
distro 1.9.0
dnf 4.19.2
fedora-third-party 0.10
file-magic 0.4.0
fros 1.1
geographiclib 2.0
geopy 2.4.1
humanize 3.13.1
idna 3.7
iso639 0.1.4
jmespath 1.0.1
josepy 1.13.0
langtable 0.0.67
libcomps 0.1.20
libdnf 0.73.1
louis 3.28.0
lxml 5.1.0
Mako 1.2.3
MarkupSafe 2.1.3
mysql-connector-python 8.4.0
nftables 0.1
olefile 0.47
packaging 23.2
parsedatetime 2.6
Paste 3.7.1
pexpect 4.9.0
pid 2.2.3
pillow 10.3.0
pip 23.3.2
ply 3.11
productmd 1.38
ptyprocess 0.7.0
pwquality 1.4.5
pycairo 1.25.1
pycparser 2.20
pycrypto 2.6.1
pycups 2.0.4
pyenchant 3.2.2
PyGObject 3.48.2
pykickstart 3.52
pyOpenSSL 23.2.0
pyparted 3.13.0
pyRFC3339 1.1
PySocks 1.7.1
python-augeas 1.1.0
python-dateutil 2.8.2
python-meh 0.51
python-pam 2.0.2
pytz 2024.1
pyudev 0.24.1
pyxdg 0.27
PyYAML 6.0.1
regex 2024.4.16
requests 2.31.0
requests-file 2.0.0
requests-ftp 0.3.1
rpm 4.19.1.1
s3transfer 0.10.1
selinux 3.6
sepolicy 3.6
setools 4.5.1
setuptools 69.0.3
simpleaudio 1.0.4
simpleline 1.9.0
six 1.16.0
sos 4.7.1
soupsieve 2.5
systemd-python 235
Tempita 0.5.2
Can anyone notice where I am going wrong?
I can run the script just fine as ./myscript.sh
and it works perfect, it's just the cron that has issues.
activate
?venv
. Just run/opt/project_1/bin/python /opt/project_1/main.py
.)HOME=/
is kind of weird, though; why do you have that?import
intry
and print the value ofsys.path
in theexcept
and thenraise
the exception again?