linux:python_cron
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:python_cron [2024/10/26 11:45] – [How to Run a Python Script in a Cron Scheduler in a Specific Anaconda Virtual Environment] jattie | linux:python_cron [2024/10/26 11:54] (current) – [How to Run a Python Script in a Cron Scheduler in a Specific Anaconda Virtual Environment] jattie | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Python Cron ====== | ====== Python Cron ====== | ||
| + | |||
| ===== How to Run a Python Script in a Cron Scheduler in a Specific Anaconda Virtual Environment ===== | ===== How to Run a Python Script in a Cron Scheduler in a Specific Anaconda Virtual Environment ===== | ||
| Line 6: | Line 7: | ||
| - **Create a Shell Script**: Write a shell script to activate the virtual environment and run your Python script. Save this script, for example, as `run_script.sh`: | - **Create a Shell Script**: Write a shell script to activate the virtual environment and run your Python script. Save this script, for example, as `run_script.sh`: | ||
| - | | + | |
| #!/bin/bash | #!/bin/bash | ||
| source / | source / | ||
| python / | python / | ||
| deactivate | deactivate | ||
| - | | + | |
| Replace `/ | Replace `/ | ||
| - **Make the Script Executable**: | - **Make the Script Executable**: | ||
| - | | + | |
| chmod +x / | chmod +x / | ||
| - | | + | |
| - **Edit the Crontab**: Open the crontab file to schedule your script: | - **Edit the Crontab**: Open the crontab file to schedule your script: | ||
| - | | + | |
| crontab -e | crontab -e | ||
| - | | + | |
| Add a cron job entry to run your script at the desired schedule. For example, to run it every hour, you would add: | Add a cron job entry to run your script at the desired schedule. For example, to run it every hour, you would add: | ||
| - | | + | |
| 0 * * * * / | 0 * * * * / | ||
| - | | + | |
| This example runs the script at the beginning of every hour. | This example runs the script at the beginning of every hour. | ||
linux/python_cron.1729943136.txt.gz · Last modified: by jattie
