Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用 lsof|wc -l 通过 crontab 定期获取打开文件的数量。它总是返回零。当我直接运行它时它给出了正确的结果。关于这种奇怪行为的任何想法?它是否与管道尺寸有关,因为结果可能非常大?非常感谢。
卡卡
主要区别在于环境变量。
在这种情况下,它可能是 PATH。lsof 通常在 /usr/sbin 中找到,当您以交互方式运行它时,它可能在您的 PATH 中,而从 cron 运行时不在 PATH 中。
试试/usr/sbin/lsof|wc -l你的 cron 脚本。并检查本地邮件,因为cron输出通常在那里发送,可能有相关的错误消息。
/usr/sbin/lsof|wc -l
它是否与管道尺寸有关,因为结果可能非常大?
不。