我发现了这个不平凡的解决方案:
#!/bin/sh
file_path=$1/script-file-name
while inotifywait -e create "$1"; test ! -f "$file_path"
do
:
done
chmod g+rw "$file_path"
chown root "$file_path"
Run Code Online (Sandbox Code Playgroud)
root该脚本必须以 的权限运行:
sudo <catch-script> /dir/where/the/target/will/be/generated
Run Code Online (Sandbox Code Playgroud)
以前,必须按如下方式更改将生成脚本的目录:
chown root /dir/where/the/target/will/be/generated
chmod 1775 /dir/where/the/target/will/be/generated
Run Code Online (Sandbox Code Playgroud)
即我们将粘性位设置为放置脚本的目录。然后指定的(捕获)脚本等待创建目标脚本,为其设置写入权限(以便生成程序能够使用它)并将所有者更改为root(以禁用删除) 。