引导一次后如何在 Solaris 中执行 运行 脚本

How to run script in Solaris after boot once

我正在寻找 运行 shell 脚本首次启动 Solaris 的正确方法。 我需要 运行 resize 命令,有一个我的脚本

#!/bin/sh -ux
echo "#!/bin/sh -ux" > /etc/rc3.d/S90scale
echo "/sbin/zpool set autoexpand=on rpool" >> /etc/rc3.d/S90scale
echo "/sbin/zpool online -e rpool c1d0" >> /etc/rc3.d/S90scale
echo "rm /etc/rc3.d/S90scale" >> /etc/rc3.d/S90scale
echo "/sbin/shutdown -y -i6 -g0" >> /etc/rc3.d/S90scale
chmod a+x /etc/rc3.d/S90scale

实际上脚本工作正常,但遗憾的是调整大小不起作用。当我从用户会话中做同样的事情时,一切都很好。

我到底做错了什么?

您的方法不是 "right" 到 运行 启动后脚本一次的方法,因为它使用旧方法。正确的方法是创建一个 smf service that runs once。但是,无论如何,它确实适用于 Solaris 10 和 11,因为 rc 脚本虽然已弃用,但仍在处理中,因此我不会详细说明 smf.

主要问题是您不检查错误,无论发生什么,它都会删除脚本并重新启动以防止进行任何分析。

我建议修改您的脚本以记录文件中发生的事情并在出现错误时退出:

#!/bin/ksh
cat > /etc/rc3.d/S90scale <<%EOF%
exec > /var/tmp/S90scale.log 2>&1 # logs everything to file
set -xe                           # show commands and exits on error
/sbin/zpool set autoexpand=on rpool
/sbin/zpool online -e rpool c1d0
mv /etc/rc3.d/S90scale  /etc/rc3.d/_S90scale
/sbin/shutdown -y -i6 -g0
%EOF%
chmod a+x /etc/rc3.d/S90scale

下次重新启动完成后,您应该查看 /var/tmp/S90scale.log 文件,可能会在那里看到一条错误消息。