我有一个python脚本myScript.py,每2秒写一个文件.但是,当我想将此脚本作为systemd服务运行时,服务可以工作但不能写入文件.
我创建了一个myscript.service文件/lib/systemd/system/
并设计如下:
[Unit]
Description=My Script Service
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/python /home/pala/PycharmProjects/myScript.py
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
并myScript.py是:
import time
while True:
with open("/home/pala/Documents/file.txt", "a") as myFile:
myFile.write("--**--")
time.sleep(2)
Run Code Online (Sandbox Code Playgroud) 我有一个时间参数,它可以是除负数和零之外的任何数字
parser.add_argument("-t", "--time",
default=2, type=int,
help="Settings up the resolution time")
Run Code Online (Sandbox Code Playgroud)
如何正确使用选项选项?