This is wrong on many levels :) ... but, it's OK, we'll make it right together.
First level
cron
is a daemon/service to execute scheduled commands ... You don't add your cron jobs to it ... you add your cron jobs to your user's crontab
like so:
crontab -e
or to root's crontab
like so:
sudo crontab -e
It will then be executed by cron
automatically ... That's it.
Second level
sh \home\Folder1\execute.sh
is a Windows style path which is not valid on Ubuntu and will translate to a single filename(not a path) like so:
sh homeFolder1execute.sh
it should be with the forward slash /
and not the backward slash e.g. :
sh /home/Folder1/execute.sh
Third level
Your export PATH="/home/Folder1"
is not the correct usage that might yield the result you expect of adding /home/Folder1
to PATH ... instead it will replace everything already in the environment variable PATH with just /home/Folder1
and that is another problem ... to just add /home/Folder1
, you should do it like so:
export PATH="$PATH:/home/Folder1"
Bonus level
As a general advice, when using crontab
in general and the root's crontab
in particular, specify the full path to the executable/s on your system(you can find it with e.g. which sh
) like so:
/usr/bin/sh /home/Folder1/execute.sh
also use the full path to executables that are used in your script e.g.:
/usr/bin/python3 -m venv venv
and:
/usr/bin/python3 /home/Folder1/main.py
and:
/usr/bin/pip install python-dotenv
Although, for the last two, it will work with just python
and pip
in a python virtual environment like you do in your script.
Otherwise, the running shell might fail in finding the path to your command/s as for example the root's environment variable PATH will return different paths from those returned by your user's PATH environment variable.
You can, however, save specifying the full path to your script file along with other scripts/files sourced/referenced in it by, first, cd
ing to the directory containing it in the crontab line like so:
cd /home/Folder1 && /usr/bin/sh execute.sh
That wont save you from not providing the full path to the executables on your system i.e. like /usr/bin/sh
, you still need to provide those ... why not the full path to cd
? you might ask ... well, the answer is cd
is a builtin shell command and will work just fine without needing a path.