我想在cronjob中运行一些代码后重新启动linux机器。运行命令后安全重启?
的代码基本上是这样的:
#!/bin/sh
do_something
reboot
其中do_something
基本上是:
function do_something {
local REPORT_URL=https://example.com/services/status
local PAYLOAD='{"message":"Update script run with success.","code":'$UPDATE_SUCCESS'}'
curl -X POST --form "payload=$PAYLOAD" "$REPORT_URL"
}
是否有可能是do_something
没有完成它的任务(例如I/O操作)之前reboot
运行?
在这种情况下,这将是这些的当中最好的解决办法:
reboot
之前添加sync
。- 在
reboot
之前加sleep 5
。 - 在
reboot
之前加上sync
和sleep
。
'do_something'究竟是什么?请显示其代码。 –