且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Cron 作业——每 5 秒运行一次

更新时间:2022-12-28 17:57:50

我不会为此使用 cron.我会使用那个 bash 脚本(使用绝对路径,除非你希望它是可移植的并且知道目录结构将被保留).

I wouldn't use cron for this. I would use that bash script (use an absolute path, unless you want it to be portable and know that the directory structure will be preserved).

相反,我会像你一样 sleep 5(只有 5 秒而不是 1 秒).

Instead, I would just sleep 5, just like you did (only 5 seconds instead of 1).

就用您的系统启动它而言,这取决于系统.在(某些)Linux 发行版上,有一个名为 /etc/rc.local 的文件,您可以在其中添加要在系统启动时运行的脚本.嗯...我不应该这么笼统,我用过的发行版都有这个.如果您运行的是 Ubuntu,则不再有 inittab,他们使用 upstart,顺便说一句.

As far as starting it with your system, that depends on the system. On (some) Linux distros, there's a file called /etc/rc.local in which you can add scripts to run when the system starts. Well... I shouldn't be so general, the distros that I have used have this. If you're running Ubuntu, there is no longer an inittab, they use upstart, btw.

因此,如果您在 /etc/rc.local 中有一个无限循环和一个条目,那么您应该为它无休止地运行(或直到遇到问题并退出)而努力.

So if you have an endless loop and an entry in /etc/rc.local, then you should be golden for it to run endlessly (or until it encounters a problem and exits).