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에는 한 줄의 메시지만 표시됩니다.

rc.local has started successfully

그렇다면 rc.local은 /sbin 폴더의 바이너리에 액세스할 수 있습니까?

rc.local스크립트의 후반부를 실행해 보는 것은 어떨까요 ?

답변1

쉘은 shebang을 사용하여 실행됩니다 #!/bin/sh -e. -e0이 아닌 상태/오류를 반환하는 첫 번째 명령에서 쉘이 종료되어야 함을 나타냅니다.

위 코드에서 grep "inet addr"일치하는 항목이 없으면 오류 1이 반환됩니다. 그러면 rc.local이 나옵니다.

grep반환되는 오류를 억제하기 위해 명령을 다음으로 변경했습니다.

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

찾기가 정말 어렵지만 Giles와 다른 사람들에게 감사드립니다.우편 엽서.

관련 정보