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.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.
[~] 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
/etc/init.d/crond.sh stop /etc/init.d/crond.sh start
Recommended Posts