简体   繁体   中英

Running a Python Script Continuously on Server

PREFACE To be completely honest, I'm new to this and am a bit overwhelmed with the number of options there seem to be in going about solving this.

I am looking to run a Python script on a server. The code is already written and involves a handful of libraries, and runs perfectly on my computer; but I want to be able to put it on a VM and have it run every 15 minutes while saving the data to a MySQL database.

Currently, the script isn't going to be accepting inputs since it is checking for changes in data via an API, but I would like to have the ability to accept inputs to the script in the future.

I know there are a few options which let you run Python on a server and the two that I have looked into mostly are Digital Ocean and Google Compute Engine. On Digital Ocean I started a droplet with django pre-installed and ran into problems with that approach and then I switched over to using Ubuntu through Digital Ocean.

I understand that you run the start command through the console, but I still don't understand how you're suppose to upload your script to the server to begin with. I have seen ssh/scp used, but I don't understand how that uploads the libraries to the sever as well.

My questions are:
- What is the best service to use (DO, Google, etc.)?
- Is Ubuntu the right approach or is django?
- Is there a basic example that someone could point me in the direction of?

Thank you for your time and I appreciate any help that you have to offer, some of the tutorials online just seem a little too robust for what I need.

What I am understanding from your question is that you want a python script to run every 15 min which does some db operation and has future scope of input parametrs.

https://en.wikipedia.org/wiki/Cron

Above will serve you well for this kind of need.

You can upload your script from local system to server via scp

scp filepath/filename.py user@ip:address:of:server:~/filepath/

Then login to server using ssh

ssh user@ip:address:of:server

Use cron to run your script every 15 minutes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM