Execute Python script with cron of TS-220

About this article

Note that I wanted to run Python scripts on a regular basis using the cron function of TS-220.

Only admin can log in with ssh. The location of the script should be /root/python/test.py. (When QNAP NAS is restarted, extra files such as in / root will be cleared, so if you want to keep it running permanently, put the script in another location or edit autorun.sh.)

reference Add items to crontab

Test script

test.py


#!/usr/bin/python
# -*- coding: utf-8 -*-
f = open("hoge.txt", "w")
f.write("hello python")

When you start it, enter "hello python" in hoge.txt in the same folder.

Editing crontab

[~] cd /etc/config Move with [~] vi crontab Add one line as shown below. This happened because it worked best as a result of various trials. I try to output the output to log.txt. */2 * * * * cd /root/python/; python test.py >> log.txt 2>&1

Restart crond

/etc/init.d/crond.sh stop /etc/init.d/crond.sh start

Recommended Posts

Execute Python script with cron of TS-220
Periodically execute python script with cron in venv environment
Manage cron jobs with python
POST json with Python3 script
Let's execute commands regularly with cron!
Execute Python script from batch file
Getting Started with Python Basics of Python
Life game with Python! (Conway's Game of Life)
10 functions of "language with battery" python
Execute Python Script during CodeSys # RunTime
Implementation of Dijkstra's algorithm with python
Coexistence of Python2 and 3 with CircleCI (1.0)
Write a batch script with Python3.5 ~
Basic study of OpenCV with Python
Basics of binarized image processing with Python
[Examples of improving Python] Learning Python with Codecademy
Check the existence of the file with python
Algorithm learned with Python 8th: Evaluation of algorithm
Clogged with python update of GCP console ①
Easy introduction of speech recognition with Python
UnicodeEncodeError struggle with standard output of python3
1. Statistics learned with Python 1-3. Calculation of various statistics (statistics)
Drawing with Matrix-Reinventor of Python Image Processing-
Recommendation of Altair! Data visualization with Python
Comparison of matrix transpose speeds with Python
Get the return value of an external shell script (ls) with python3
Script python file
I tried hundreds of millions of SQLite with python
FizzBuzz with Python3
AWS-Perform web scraping regularly with Lambda + Python + Cron
Introduction of Python
Scraping with Python
Prepare the execution environment of Python3 with Docker
Automatic operation of Chrome with Python + Selenium + pandas
Performance comparison of face detector with Python + OpenCV
2016 The University of Tokyo Mathematics Solved with Python
python script skeleton
Scraping with Python
Algorithm learned with Python 13th: Tower of Hanoi
Python with Go
Color page judgment of scanned image with python
[Note] Export the html of the site with python.
Clogged with python update of GCP console ② (Solution)
Calculate the total number of combinations with python
Python script profiling
Twilio with Python
Integrate with Python
Use multiple versions of python environment with pyenv
Check the date of the flag duty with Python
Import python script
Play with 2016-Python
Periodically execute Python Script on AWS Data Pipeline
Solve A ~ D of yuki coder 247 with python
AES256 with python
Tested with Python
Basics of Python ①
1. Statistics learned with Python 1-2. Calculation of various statistics (Numpy)
Basics of python ①
[Python] Get rid of dating with regular expressions
python starts with ()
Script to tweet with multiples of 3 and numbers with 3 !!