我正在尝试在重新启动时使用 systemd 删除特定目录中的所有文件。
这是我的/lib/systemd/system/delete-at-boot.service
文件(root,访问 644):
[Unit]
Description=Remove content of test folder at boot
[Service]
ExecStart=/bin/rm /home/user/test/*
[Install]
WantedBy=multi-user.target
当我/bin/rm /home/user/test/*
手动运行时,删除工作正常,但是当我开始该过程时,我可以看到我的文件没有被删除。
● delete-at-boot.service - Remove content of test folder at boot
Loaded: loaded (/lib/systemd/system/delete-at-boot.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2019-08-02 18:21:09 UTC; 7s ago
Process: 5460 ExecStart=/bin/rm /home/user/test/* (code=exited, status=1/FAILURE)
Main PID: 5460 (code=exited, status=1/FAILURE)
Aug 02 18:21:09 tegra-ubuntu systemd[1]: Started Remove content of test folder at boot.
Aug 02 18:21:09 tegra-ubuntu rm[5460]: /bin/rm: cannot remove '/home/user/test/*': No such file or directory
Aug 02 18:21:09 tegra-ubuntu systemd[1]: delete-at-boot.service: Main process exited, code=exited, status=1/FAILURE
Aug 02 18:21:09 tegra-ubuntu systemd[1]: delete-at-boot.service: Unit entered failed state.
Aug 02 18:21:09 tegra-ubuntu systemd[1]: delete-at-boot.service: Failed with result 'exit-code'.
我相信问题与“*”有关,但我不确定替换它的最佳方法是什么。
通配符不应该像在
systemd
服务中那样使用。将您更改ExecStart
为:现在它应该正确执行该操作。