Fght
Posts: 319
Joined: Thu Feb 05, 2015 10:26 pm

my pi's website stopped working

Mon Jul 20, 2015 4:58 pm

when i run the duck dns './duck.sh' to try to test it it says no such directory (linux cron installation)

what should i do? perhaps install the duck dns again? if yes what happened to it ?

Fght
Posts: 319
Joined: Thu Feb 05, 2015 10:26 pm

Re: my pi's website stopped working

Mon Jul 20, 2015 7:07 pm

where can i get help with lighttpd and duckdns?
i really want my site to return and i've tried the duck installment again already with no results

sixbacon
Posts: 13
Joined: Sun Jan 22, 2012 4:22 pm

Re: my pi's website stopped working

Thu Aug 06, 2015 8:40 pm

I have struggled a bit with setting up duckdns on the RPi, but got there in the end. Here’s what I did.

I wanted use a dns service to access IOT units in my house and wanted the RPi to talk to the duckdns server every five minutes to keep my domain on the duckdns pointing at the correct IP. The instructions on the duckdns site are a bit opaque to ordinary mortals and didn’t quite work for me.

I tried using sudo in front of the commands but it made no difference, so it is not necessary.

1. Create a script file on the Rpi to contact the duckdns site. Create a directory and then the file. Do this in your home directory, /home/pi, usually. Open a terminal window and type - mkdir duckdns, after the prompt, mine is [email protected] pi ~$

[email protected] pi ~$ mkdir duckdns

then go to that directory

[email protected] pi ~ $ cd duckdns

create the script file using nano , by typing - nano duck.sh

[email protected] pi ~ /duckdns $ nano duck.sh

Now you need the name of the domain you created when you signed up to duckdns say MYIOT and the long token, or security code you were issued with, something like
a7c4d0ad-114e-40ef-ba1d-d217904a50f2

The script file will call the program curl, a command line tool that will send data or request data from a server, in this case duckdns.org. The instruction curl is to use is piped to it using the echo command. You need to put in the path to your duckdns directory as it appears on your computer. On my machine this /home/pi. So enter precisely,

echo url="https://www.duckdns.org/update?domains= ... 4a50f2&ip=" | curl -k -o /home/pi/duckdns/duck.log -K –

all in one line, replacing the domain name, the token and path with your values. Pay attention to the quotation marks, spaces, vertical line, the & symbols. The various parameters after the curl command are directives, google for details. A log file, duckdns.log, is created, which is overwritten each time (single >), with the results of the curl call. All it will contain is ”OK”, if it is successful. You can use leafpad to edit the script file and cut and paste from the duckdns web site if you find this easier.

(If like me you want to check it runs every five minutes for the first few days, add a second line to the script file

date >> /home/pi/duckdns/time.log

This will add to the time.log file each time the script runs, (>> ) with the date and time the script ran. This file will grow and grow, so delete the line from the script, once you are happy it is running.)

Close nano with CTRL X, y, Return.

2. Make the script an executable file, by typin g- chmod 700 duck.sh

[email protected] pi ~ /duckdns $ chmod 700 duck.sh

It is best to test the file works, type - ./duck.sh

[email protected] pi ~ /duckdns $ ./duck.sh

It should return something like

%Total % Received % Xfred Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2 0 2 0 0 0 --:--:-- 0:00:02 --:--:-- 1
[email protected] pi ~ /duckdns $

Then have a look at the log file, type cat duck.log

[email protected] pi ~ /duckdns $ cat duck.log
OK [email protected] pi ~ /duckdns $

Note the “OK” at the start of the line, the conents of the file. That shows it is working.


3. Set up program cron to run this script at 5 min intervals by editing the text file that drives cron by typing, crontab -e
[email protected] pi ~ /duckdns $ crontab -e

This will open a text editor and show the current contents with several lines of instructions with # to indicate comment lines. There may be data lines at the end of these, go to a the start of a blank line below everything and enter precisely

*/5 * * * * /home/pi/duckdns/duck.sh >/dev/null 2>&1

Again noting the spaces and replacing the path with the correct one for your machine. This tells cron to run the script , duck.sh, every 5 min and send the output and any error messages(2>&1) to a an empty file (null). I found I had to put in the full path to get it to work, unlike the instructions on duckdns.org, which used the path shortcut “~”.

Exit the editor using Ctrl X, y, Return. Assuming all is correct you should see,

[email protected] pi ~$ crontab –e
crontab: installing new crontab

To check it is working look at the date on the duck.log file, or delete the log file and see when it is created again. (If you added the date line to script file, look at the time.log file, using

[email protected] pi ~$ cat time.log

or viewing it in leafpad.)

Hopefully not to long winded, but I wanted to explain the steps so you can trace faults more easily.
sixbacon

User avatar
DougieLawson
Posts: 36818
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: my pi's website stopped working

Thu Aug 06, 2015 8:55 pm

I think it's exceedingly long winded.

I run this

Code: Select all

#!/bin/bash

OLDaddr=$(head -1 /home/pi/ipaddr.saved.txt)
IPaddr=$(printf '\42';dig +short myip.opendns.com \@resolver1.opendns.com | awk '{printf "%s",$0}';printf '\42')

if [ $IPaddr == '"0.0.0.0"' ]; then
  exit 20
fi

if [ $OLDaddr != $IPaddr ]; then
  NOW=$(date +"%d/%m/%Y, %T,")
  printf "$NOW New address found\r\n"
  echo -e $NOW$IPaddr >> /home/pi/ipaddr.log.txt
  echo $IPaddr | tee /home/pi/ipaddr.saved.txt
  printf "\r\n"
  curl -s -o - --user dnsOmaticuserid:dnsOmaticpassword  https://updates.dnsomatic.com/nic/update
  printf "\r\n"
  # NOT needed - done by DNS-O-Matic  ==>  curl -s -o - "https://www.duckdns.org/update?domains=domain1,domain2&token=axxxae55-xaxx-xcxx-xxxx-fxxxxdb644af&ip="
  printf "\r\n"
fi
every 5 mins from cron. http://dnsomatic.com does the update for everything including DuckDNS. It only gets called if the IP address returned from the DIG command has changed from last time. (Currently my address hasn't changed since 17th July.)

I also get a complete log of every address assigned and the date/time that happened and because I'm running it from cron, cron will also generate an email (which I can send out to gmail).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Troubleshooting”