rc.localが/sbin/ifconfigコマンドを実行していません。

rc.localが/sbin/ifconfigコマンドを実行していません。

/etc/rc.localコード、

echo "rc.local has started successfully" > /home/sk/tmp/init.log

isEthConfigured=$(ifconfig eth0 | grep "inet addr")
echo "rc.local has run ifconfig command well, with result - $isEthConfigured" >> /home/sk/tmp/init.log

if [[ -z "${isEthConfigured// }" ]];then
  echo "changing the iptables stuff" >> /home/sk/tmp/init.log
  sudo iptables -A OUTPUT -d 10.199.48.0/24 -j REJECT
fi

echo "rc.local has completed successfully" >> /home/sk/tmp/init.log
exit 0*

eth0 インターフェイスを使用しない場合は、iptables ルールを追加します。ただし、rc.localはifブロック内のコードを実行しません。

私のinit.logには1行のメッセージしか表示されません。

rc.local has started successfully

もしそうなら、rc.localは/ sbinフォルダのバイナリにアクセスできますか?

rc.localスクリプトの後半を実行してみてはいかがでしょうか?

ベストアンサー1

シェルはshebangを使用して実行されます#!/bin/sh -e-eゼロ以外の状態/エラーを返す最初のコマンドでシェルを終了する必要があることを示します。

上記のコードにgrep "inet addr"一致するものがない場合、エラー1が返されます。これでrc.localが表示されます。

grep返されるエラーを抑制するために、コマンドを次のように変更しました。

isEthConfigured=$(ifconfig eth0 | grep "inet addr"  || :)

見つけるのは本当に難しいですが、ギルズと他の人に感謝します。郵便はがき

おすすめ記事