- First, activate your virtual environment using the command:
source /path/to/virtualenv/bin/activate
- Now, you can run your python script inside the virtual environment
python /path/to/script.py
- To run this script at a specific time or interval, you can add a cron job.
crontab -e
This command will open the cron configuration file, where you can add new jobs.
- Add a new line with the following format:
* * * * * /bin/bash -l -c '/path/to/virtualenv/bin/activate && python /path/to/script.py'
This line tells cron to run the command every minute (* * * * *), activate the virtual environment, and then run the Python script. You can change the values in the first 5 fields of the line to specify the schedule of the cron job.
-
Save the file and exit.
-
Verify that the cron job was added by running
crontab -l
This will list all the cron jobs that are currently running.
- To remove a cron job you can use `