假设计算机启动不正常。我想每月一次在启动时运行某个脚本。但是我无法设置cron作业,因为我不知道计算机是否会在此日期启动。
我虽然关于这种方法。
if(file_exists("last_boot.txt"))
{
if(<<more then a month has passed since last date time>>)
{
<<run script>>
}
}
else
{
<<run script>>
}
<<write current date time into the file>>
可以使用某些标准工具来完成操作而无需使用文件技巧吗?
只需*使用cron在任一计划中运行它,然后在脚本中检查计划的其他部分:
单程:
@reboot /path/to/my_script.sh
if has_run_this_month() {
exit
}
另一种方式:
0 0 1 * * /path/to/my_script.sh
if has_run_since_reboot() {
exit
}
*这种运行方式存在一些问题:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句