【发布时间】:2017-04-04 04:30:52
【问题描述】:
我想在 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 是否有可能在 reboot 运行之前没有完成所有工作(例如 i/o 操作)?
在这种情况下,这些解决方案中最好的解决方案是什么:
- 在
reboot之前添加sync。 - 在
reboot之前添加sleep 5。 - 在
reboot之前添加sync和sleep。
【问题讨论】:
-
do_something到底是什么?请显示它的代码。