我有可以从同一台计算机上的不同用户运行的脚本。该脚本应在每次运行时将日志写入同一文件。
脚本的最小版本:
#!/usr/bin/env bash
# 2
touch /var/tmp/lll.log # 3
chmod 666 /var/tmp/lll.log # 4 (You can comment this line, but this will change nothing)
echo ghghhghg >> /var/tmp/lll.log # 5
从 root 启动然后从其他用户启动时没有问题,但顺序相反时会抛出错误。
./savetmp.sh: line 5: /var/tmp/lll.log: Permission denied
ls -ld /var/tmp /var/tmp/lll.log 的输出:
.rw------- 9 armoken 1 May 10:52 /var/tmp/lll.log
drwxrwxrwt - root 1 May 10:52 /var/tmp
猫 /proc/sys/fs/protected_regular:
1
如何解决这个问题?