如何使用标志将这 2 个脚本组合到 运行 多个 cronjobs?

How do I combine these 2 scripts to run multiple cronjobs using flags?

我有两个相似的脚本。第一个每天在特定时间运行一次并在该时间打印“成功”消息。

if [[ $status == 200 ]]; then
    echo "success"
else
    echo "error"
fi

第二个脚本每 30 分钟运行一次,除非出现错误,否则不打印任何内容。

if [[ $status != 200 ]]; then
    echo "error"
fi

我 运行 都在使用 cron 作业。

0 11 * * * /home/username/script1.sh
*/30 * * * * /home/username/script2.sh

我想知道如何最好使用 flags 组合这两个脚本。基本上我想要一个脚本,它可以每天早上 9 点发送一条成功消息,同时也可以 运行 每 30 分钟发送一次成功消息,而不会一次又一次地发送该成功消息,然后只在出现故障时才发送错误消息。

我确实得到了组合脚本的解决方案: 但我对如何使用 flags 感到困惑,因为我对它们不太熟悉.

添加一个标志 --error-only 并在脚本中检查它。

if [[ $status == 200 ]]; then
    if [[ "" != "--error-only" ]]; then
        echo "success"
    fi
else
    echo "error"
fi

然后修改 crontab 以传递该标志,但其中一次运行除外。

0 11 * * * /home/username/script1.sh
*/30 0-10,12-23 * * * /home/username/script1.sh --error-only
30 11 * * * /home/username/script1.sh --error-only