LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script works different as startup script - any ideas ? (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-works-different-as-startup-script-any-ideas-4175507748/)

robinaspey 06-11-2014 11:56 AM

Bash script works different as startup script - any ideas ?
 
I am testing a bash shell script which works ok from root login at the command line. The script runs on a DD-WRT linux router and is as follows:

#!/bin/sh
x=0
echo "Waiting for IP on WANUP" >> /opt/logs/debug.log
while [ $x -lt 30 ]; do
sleep 2
echo "Retries:$x/30; IP: $(curl -s http://icanhazip.com)" >> /opt/logs/debug.log
let x=x=1
done
echo "Finished " >> /opt/logs/debug.log

The script has the following name wanup.ipup so that it runs
when the connections comes on. It all works correctly but
for some reason when running as a startup script rather than
from the command line, the curl command returns a null instead
of the WAN IP address

The script was made executable e.g. chmod +x wanup.ipup
and other than the curl part it works find and executes
on startup but the file debug.log reveals no IP addresses
logged.

Any ideas how to fix the curl -s http://icanhazip.com
part so I get the IP address on startup properly. ?

smallpond 06-11-2014 01:49 PM

Looks like your loop should never end, since x is not incremented.
Most likely curl is not in the script's PATH. Specify the absolute path for all executables: /usr/bin/curl.

robinaspey 06-11-2014 02:07 PM

yes there was a typo which stops the counter incrementing, wasnt
able to paste back from Putty...so typed in manually.

And guess what.. now it works ..!

Very much appreciated from this side of the pond :)


All times are GMT -5. The time now is 11:10 PM.