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