小编Séb*_*rre的帖子

18.04.4 关机时删除文件

如果我重新启动或关闭我的 Ubuntu 18.04.4,我想删除一个锁定文件。

我创建了“usr/local/sbin/delete_lock.sh”

#!/bin/bash
lock="/home/sebastien/rsync.lock"
if [ -f "$lock" ];
rm $lock;
fi
Run Code Online (Sandbox Code Playgroud)

然后是另一个“/etc/systemd/system/run_on_shutdown.service”:

[Unit]
Description=Delete lock file at shutdown - /etc/systemd/system/run_on_shutdown.service
DefaultDependencies=no
Before=shutdown.target halt.target
# If your script requires any mounted directories, add them below: 
RequiresMountsFor=/home

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/delete_lock.sh

[Install]
WantedBy=halt.target shutdown.target
Run Code Online (Sandbox Code Playgroud)

然后我启动

sudo systemctl enable run_on_shutdown.service
Run Code Online (Sandbox Code Playgroud)

并重新启动

知道为什么不删除 rsync.lock 文件吗?非常感谢

reboot bash shutdown rsync

5
推荐指数
1
解决办法
1200
查看次数

标签 统计

bash ×1

reboot ×1

rsync ×1

shutdown ×1