I am using my raspberry to run a discord bot and usually i ssh into it and run
source file/bin/activatepython file/main.py
i tried adding those commands to crontab hoping it'd work but it does not
@reboot source file/bin/activate &@reboot python file/main.py
i am fairly new to this and i just followed youtube so far to set stuff up. anyone know how to get my main.py file running on reboot?
oops.se
Did you sudo crontab -e editing the crontab?
winikolo
yup
oops.se
Then you run as root
oops.se
Don't use sudo
k9t33n
this still opens a venv but it will not open it in the same terminal as the one you log into with ssh
im trying out your method of creating a bash file with source and the python command in it
winikolo
but that causes python errors for some reason
winikolo
AYYYYYY WE GOT IT
winikolo
apparently it couldnt read upto the cogs folder for some reason
winikolo
went only until home/winikolo/
winikolo
bruh even with that fixed nothing is happening when i run the bash off crontab wtf, but manually running it works?
inwamos
Cd into your bot’s directory
inwamos
Then, run python after cd into your main.py
inwamos
Or simply specify the absolute path to all your files
inwamos
Or learn how to use docker instead. It gives you a variety of different options such as autostart a container on startup and so on
inwamos
+ docker is a great hard skill for your it future 😛
winikolo
I fixed the python errors by absolute path, yes, but what i want is for the bash script that runs the virtual env + main.py file to start on reboot, manually when i run it as in './start_script.sh' it works but when using cron tab to run it on reboot, it doesnt work
winikolo
Idk if theres a way to see what the errors crontab sees but idk tbh