Setting up Python algos to run on Ubuntu startup using crontab

If you’re using Ubuntu or some other flavor of Linux you more than likely want your algorithm to start with the server. This is a pretty straightforward process.

The first thing you’ll want to do is make sure cron is installed

sudo apt-get update
sudo apt-get install cron

Next run crontab -e select nano when it asks which editor. The code below can be used as a template The first two lines are just writing the current date to the log files on reboot so you know when the server was restarted.

@reboot date >> /home/me_jeremywhittaker_com/AAII/log.txt
@reboot date >> /home/me_jeremywhittaker_com/AAII/errors.txt

    

I actually am running two scripts for this particular strategy. Each one gets its own line of code. This basically tells it to run on on startup @reboot then the path to the script to execute,

@reboot /home/me_jeremywhittaker_com/queen_of_stonks/queen_of_stonks_monitor.py >> /home/me_jeremywhittaker_com/queen_of_stonks/logs.txt 2>> /home/me_jeremywhittaker_com/queen_of_stonks/errors.txt 

@reboot /home/me_jeremywhittaker_com/queen_of_stonks/queen_of_stonks_trade.py >> /home/me_jeremywhittaker_com/queen_of_stonks/logs.txt 2>> /home/me_jeremywhittaker_com/queen_of_stonks/errors.txt

That’s it. We can now do a sudo reboot and our scripts should start with our server and save to the log files indicated.

Leave a Reply