Report this

What is the reason for this report?

How to use a virtual machine?

Posted on September 21, 2020

How do I use a virtual machine? I have created a droplet and now I want to code in python and have the machine run on its own. Lets say at 12pm everyday I want it run a function and save the result to my local hard drive, how do I do this?

Thanks.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi, you’ve described a common use case for cron, a common facility on unix/linux. Here’s a tutorial on setting up cron, including how to set the time and save the result to a hard drive - either as a new file or appending an existing file:

How To Use Cron To Automate Tasks On a VPS

More handy info and a crontab generator app here, too: https://crontab.guru/#0_12_*_*_*

That’s the link for an example crontab setting that will execute every day at 12:00 server time.

Hope this helps - let us know if you have any more questions.

Heya,

To achieve your goal of running a Python function daily at 12 PM on a DigitalOcean Droplet (a virtual machine), and then saving the result to your local hard drive, you’ll need to set up a few things both on your Droplet and your local machine.

Make sure your Script is located on your Droplet

In order for your Droplet to execute your script it should be located on it’s hard disk.

You can either transfer it using scp or just create a new file and paste the contents of your script in it.

Step 2: Scheduling the Script

  1. Install Cron (if not already installed):
sudo apt update
sudo apt install cron
  1. Schedule Your Python Script Using Crontab:
crontab -e

Add the following line to run your script daily at 12 PM server time:

0 12 * * * /usr/bin/python3 /path/to/your/task.py

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.