Linux startup init.d file always fails with follow

2019-08-30 11:50发布

问题:

I have the following bash script to update to my website my current ip. It works fine stand alone, but put into a startup file, fails upon startup. I'm guessing it's a sequencing thing, but I'm not sure how to fix the sequencing, and after a few hours of googling and trying everything I can think of, I'm hoping someone can lead me in the right direction! This is what I am trying to run:

#!/bin/sh

IP_ADDR=$(ifconfig eth0 | sed -rn 's/^.*inet addr:(([0-9]+\.){3}[0-9]+).*$/\1/p')
wget -q -O /dev/null http://example.com/private/RPi_IP.php?send=${IP_ADDR}

I can't figure out what to do. I tried adding it to other startup programs even, and it fails upon startup too. I'm using a Raspberry Pi. Any ideas?

回答1:

Your path might not be what you expect. You should fully-qualify any commands that you use. Especially for programs that live in /sbin/

ie

/sbin/ifconfig
/usr/bin/sed
/usr/bin/wget


标签: linux bash