使用rc.status在新SLES上执行两次的Bash脚本

时间:2018-04-17 20:17:21

标签: bash sles

我有一个奇怪的现象,当我们从SLES 11迁移到SLES 12(SuSE Enterprise Linux)时,一个长期的管理脚本开始或多或少地运行两次。我可以使用最小示例/etc/rc.status跟踪此与test.sh相关:

#!/bin/bash
echo Sourcing rc.status
. /etc/rc.status
echo End of script

status作为参数(我的脚本的常见用例)运行时...

./test.sh status

......我观察到这个输出:

Sourcing rc.status
Sourcing rc.status
End of script
End of script

是什么给出了?

1 个答案:

答案 0 :(得分:0)

事实证明,SLES /etc/rc.status文件中存在一些问题:

user@host:~> diff rc.status.sles11 /etc/rc.status
34a35,92
> # Check if the service is used under systemd but not started with
> if test -z "$SYSTEMD_NO_WRAP" && /usr/bin/mountpoint -q /sys/fs/cgroup/systemd; then
>     if test $PPID -ne 1 -a $# -eq 1 ; then
>       _rc_base=
...

因此解决方案是在采购SYSTEMD_NO_WRAP之前设置/etc/rc.status

#!/bin/bash
echo Sourcing rc.status
SYSTEMD_NO_WRAP=1
. /etc/rc.status
echo End of script

这给出了预期的行为:

Sourcing rc.status
End of script