Tuesday, January 11, 2011

Step one of my website

This post focuses on the initial step I took to have my new website up and running. The domain part.

What is assumed here is a little understanding of Linux and a some drive towards getting things done.

First I had to find out how my provider(GratisDNS) would like the data - luckily for me it turned out that I only have to provide very few parameters in a URL String and then it would automigaclly read the IP from where I sent it. All set with the information, now on to creating a little script.

Knowing that I had to call a "simple" URL, and by reading on the forums(very supportive forum over at GratisDNS), I found that using curl is by far the easiest. So my script looks like this:

curl -s "https://ssl.gratisdns.dk/ddns.phtml?..params.."

curl is a nice little program, that can request a server by HTTP[1]. The "-s" option makes it run silent and then theres the URL, remember the double quotes around the URL. That all there is to making the script - remeber to save it in a location where the user you are planning to run it as, has execute-rights.

To the crontab - this is the abstract part. First we need to gain an understanding of the software. I do this by asking: What does it do? it schedules another piece of software to run. What software? Anything that you can run on a command line. So that should give a basic understanding.

How do we do it then? we utilize the crontab command it has three options L(ist), E(dit) and R(emove) so you wan't to edit the crontab - cool "crontab -e" opens up your editor and you are ready to rumble.

I have taken the liberty to borrow some of this nice graphic from http://www.crontabrocks.org/:
______________________ 1. Minute - Minutes after the hour (0-59)
|  ____________________ 2. Hour - 24-hour format (0-23).
| |  __________________ 3. Day - Day of the month (1-31)
| | |  ________________ 4. Month - Month of the year (1-12)
| | | |  ______________ 5. Weekday - Day of the week. (0-6, where 0 indicates Sunday)
| | | | |
* * * * * /some/script/or/command
To explain it, the first part(the star-ish one) is the scheduling part, the other part is your command - this could be anything, in our case a shell script.

The interesting part is the first one, the scheduling. First of all there is a special value, identified as an asterisk(*), this tells cron to do it every-something. And as stated by the descriptive labels, each of the starts represents a time unit.

  1. The minute(s) within the hour
  2. The hour(s) within the day - 24 hour clock, zero based.
  3. The day(s) within the month
  4. The month(s) within the year
  5. The day(s) within the week, better known as weekday.
Specifying a value for any of them would result in the command being executed every time there's a match.
For example one could write:
0 0 1 * * /path/to/script --parameter
This would be run on the first day of every month the zeroth minute of the zeroth hour.

So by playing around with cron and getting to know the format, I decided that my script should run hourly, or more precise, it should run on the 30'th minute of every hour. So the cron expression looks like this:
30 * * * * /home/nwillems/gratisdns_ddns.sh


I belive that hourly is fine, and then setting it to that minute seems like a bit odd, instead of just setting it to the zeroth minute. I was wondering though, if I should make it run half hourly, then the cron expression would look like this:
0,30 * * * * /home/nwillems/gratisdns_ddns.sh

What with the coma, you ask? That is cron's way of defining a list of time-unit. So for example "0 0,12 * * *" would mean something running each half a day(midnight and noon).

That really was all that needed to be done - and off you go with your own "custom" made Dynamic DNS.

If anyone cares out there - I found a special little article, I found it quite amusing reading: http://gizmodo.com/5716226/so-you-wanted-to-be-a-computer-programer

/* EDIT _Fixed pre environment around needed places */

[1]=If your interested you should go read the man page - http://curl.haxx.se/docs/manpage.html

1 comment:

Anonymous said...

Cool blog, jeg glæder mig til at lære/læse mere i fremtiden

Choose a month: