我有一个非常奇怪的问题,我可能没有正确烹饪,但我尝试了一个最小的例子:
在20.04的lxd容器中,我试图运行由incron触发的作业。以我最小的例子来说,这是我的incron系列:
/home/scanfiler/test IN_CLOSE_WRITE /home/scanfiler/test.sh &>> /tmp/log-scanfiler-test这是我的测试脚本
#!/bin/bash
logger "Starting"
touch /tmp/test/test-$(date +%s)-1
touch ~/test_out/test-$(date +%s)-1
sleep 20
touch /tmp/test/test-$(date +%s)-2
touch ~/test_out/test-$(date +%s)-2
logger "Done"我正在写入日志,然后在主文件夹中创建一个文件,在tmp文件夹中创建一个文件,然后等待20秒(这将给我在运行时检查的时间,以防tmp立即被清除),然后我将写入更多的文件。
这就是发生的事情:
scanfiler ~scanfiler # rm test/testblah && touch test/testblah
scanfiler ~scanfiler # journalctl -xe|tail
Aug 17 14:59:26 scanfiler incrond[2526]: PATH (/home/scanfiler/test) FILE (testblah) EVENT (IN_CLOSE_WRITE)
Aug 17 14:59:26 scanfiler incrond[2526]: (scanfiler) CMD (/home/scanfiler/test.sh &>> /tmp/log-scanfiler-test)
Aug 17 14:59:26 scanfiler scanfiler[1250558]: Starting
scanfiler ~scanfiler #
scanfiler ~scanfiler # ls /tmp/test
scanfiler ~scanfiler # ls test_out
test-1597669166-1
scanfiler ~scanfiler # journalctl -xe|tail
Aug 17 14:59:26 scanfiler incrond[2526]: PATH (/home/scanfiler/test) FILE (testblah) EVENT (IN_CLOSE_WRITE)
Aug 17 14:59:26 scanfiler incrond[2526]: (scanfiler) CMD (/home/scanfiler/test.sh &>> /tmp/log-scanfiler-test)
Aug 17 14:59:26 scanfiler scanfiler[1250558]: Starting
scanfiler ~scanfiler # journalctl -xe|tail
Aug 17 14:59:26 scanfiler incrond[2526]: PATH (/home/scanfiler/test) FILE (testblah) EVENT (IN_CLOSE_WRITE)
Aug 17 14:59:26 scanfiler incrond[2526]: (scanfiler) CMD (/home/scanfiler/test.sh &>> /tmp/log-scanfiler-test)
Aug 17 14:59:26 scanfiler scanfiler[1250558]: Starting
Aug 17 14:59:46 scanfiler scanfiler[1250627]: Done
scanfiler ~scanfiler # ls /tmp/test
scanfiler ~scanfiler # ls test_out
test-1597669166-1 test-1597669186-2
scanfiler ~scanfiler # ls /tmp/log-scanfiler-test
ls: cannot access '/tmp/log-scanfiler-test': No such file or directory如您所见,即使在运行时,也不会创建tmp文件,而主目录中的文件也在其中。最终,即使是应该在tmp中的日志文件也不存在。当同一个用户在控制台中运行时,一切正常,所以我的tmp权限可能不会被破坏。
有人能告诉我这里发生了什么吗?我的脚本中有更奇怪的问题(在控制台中运行时运行得很好),但是它们可能是相关的,所以我想先解决这个问题。
发布于 2020-08-17 15:11:20
好吧,正如评论中所暗示的,我明白了。我留下这个答案是因为我没有在google上找到任何关于incron (或cron)和tmp目录的信息,而且这些机制看起来相当新(在我以前的18.04安装中没有)。
金龙的系统服务已经有了
PrivateTmp=true这将导致服务在/tmp下面有一个私有tmp目录。我不想要这种行为,所以我使用
systemctl edit --full incron.service并删除行(从/lib/.中创建原始服务文件的新版本)。在/etc/.中)。
在此之前,我还观察到了一些更奇怪的行为,在私有tmp目录中存在权限问题,但由于其他原因,我没有进一步调查,因为我需要一个全局tmp。
https://askubuntu.com/questions/1267918
复制相似问题