Syntax error while trying to setup watchdog script

Hi everyone,

I recently setup a vpn on my router everything mostly works fine, the one thing that is nagging me here is that once or twice everyday my VPN connection drops and I have to manually go to VPN >> OpenVPN >> stop/start.

Now, I found a watchdog script:

#!/bin/sh
n=0
while [ $n -lt 10 ]
do
if /bin/ping -c 1 8.8.8.8 >/dev/null
then
exit 0
fi
n=$((n+1))
done
/etc/init.d/network restart

I have made it executable, however, when try to test run it by

sh /root/wan-watchdog.sh

It gives me a

/root/wan-watchdog.sh: line 11: syntax error: unexpected end of file (expecting "then")

Can anyone please provide me any sort of solution as to why this happening.

Thanks.

Oops sorry I should say that I've modified the last,

/etc/init.d/network restart

with

/etc/init.d/openvpn restart

Thanks.

Not sure how the script was placed on your device, try hexdumping it and inspect the bytes may reveal something.

hexdump -C /root/wan-watchdog.sh

I, unforutnatly, am not an expert on this matters. Here the output, if that helps:

00000000 23 21 2f 62 69 6e 2f 73 68 0d 0a 6e 3d 30 0d 0a |#!/bin/sh..n=0..|
00000010 77 68 69 6c 65 20 5b 20 24 6e 20 2d 6c 74 20 31 |while [ $n -lt 1|
00000020 30 20 5d 0d 0a 64 6f 0d 0a 20 20 69 66 20 2f 62 |0 ]..do.. if /b|
00000030 69 6e 2f 70 69 6e 67 20 2d 63 20 31 20 38 2e 38 |in/ping -c 1 8.8|
00000040 2e 38 2e 38 20 3e 2f 64 65 76 2f 6e 75 6c 6c 0d |.8.8 >/dev/null.|
00000050 0a 20 20 74 68 65 6e 0d 0a 20 20 20 20 65 78 69 |. then.. exi|
00000060 74 20 30 0d 0a 20 20 66 69 0d 0a 20 20 6e 3d 24 |t 0.. fi.. n=$|
00000070 28 28 6e 2b 31 29 29 0d 0a 64 6f 6e 65 0d 0a 2f |((n+1))..done../|
00000080 65 74 63 2f 69 6e 69 74 2e 64 2f 6f 70 65 6e 76 |etc/init.d/openv|
00000090 70 6e 20 72 65 73 74 61 72 74 |pn restart|
0000009a

Problem solved the actual culprit here was drum roll 'Notepad++. After lots searching on the internet I came across this stackexchange thread.

The issue has had something to do with the white spaces. Following the advice mentioned in that thread. After saving my script in Notepad++. I converted my script with the help of this website, and then I uploaded the converted script to my router. And this time I got no syntax error.

P.S.: Although the script so far hasn't been working. But that isn't in the scope of this thread. I believe, as the popularity of OpenWrt is rising. The developers of this project do need to incorporate some everyday users friendly features like "basic connection wizard," (as getting internet connection on my OpenWrt wasn't less of struggle) and "watchdog" script.

Thanks.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.