Crapple Quite.

2Jun/12Off

Quick and dirty Crontab tutorial

For those who have used Linux for any length of time the issue of automating tasks will have come up. The time honoured way of doing this is through Cron. Each user on a Linux system has a crontab - a list of commands that is run at a predetermined time.

I'm not going into massive detail into what Cron is and how it works - the MAN page is a good start for that. However in order to automate tasks you need to put them into your crontab, and here is how you do that.

1. Type 'crontab -e' into the shell prompt. This will let you edit the crontab file, on some distributions (CentOS, Fedora) the editor will be Vi (or Vim) or in case of Debian and Ubuntu (and maybe others) it is nano.
2. Enter the timing and command - use must you absolute pathnames for everything.
The way crontab files are formatted is something like this:

*1  *2  *3  *4  *5 <command>

*1 = minute of the hour (0 - 59)
*2 = hour of the day (24 hour clock, 0 - 24)
*3 = week of the month (0 - 52)
*4 = month of the year (0 - 12 where January = 0)
*5 = day of the week (0 - 7 where Sunday = 0)
<command> = command using absolute paths

So for example if I wanted to run /home/crapple/runme.sh every Monday at 1am I would put the following in the crontab:

* 1 * * 1 /home/crapple/runme.sh

Basically * means every minute during 1am on Monday, so the script will run 60 times. If you want it to run only once, pick a minute and change the first * to a number between 0 and 59.

Once you have entered the command you wish to run, save the file and quit - so in Vi/Vim, escape edit mode and :wq as normal or in nano ctrl+o then ctrl+x.

And you're done. Just remember if your script outputs to STDOUT then when it runs the output will be placed in your user account's email. This can be suppressed by putting > /dev/null at the end of your command, so using our previous example:

* 1 * * 1 /home/crapple/runme.sh > /dev/null

Now all input will be sent to /dev/null.

One final thing, if you want to comment your crontab file to make it understandable at a later date, single line comments start with a #, for example

* 1 * * 1 /home/crapple/runme.sh > /dev/null # this is a comment

Happy automation!

20Feb/09Off

Mediatomb on Debian howto

In truth calling this a howto is a lie because it is so easy. That is to say, getting the basics up and running is so easy. After that you should really do some further reading (don't worry I'll provide the links), but a quick and dirty setup is surprisingly easy.

Before the end of last year I decided it was time to make a move away from FreeBSD to Linux on the server front. It's not particularly that FreeBSD is bad or become bad but since the middle of 2008 I had been playing around with Xen virtualisation using CentOS as the host OS and quite frankly I was blown away. Xen on FreeBSD is far from trivial. Anyhow, aside from the religious arguments with FreeBSD and Linux (quite frankly both are great server OSes (although Linux isn't really an OS but rather a kernel) just use which you prefer or gets the job done) I knew it would either boil down to CentOS or Debian. I chose Debian in the end because Lenny had just come out and quite frankly I felt like it (there's no good reason either way in my mind).

I wanted a nice way of streaming music (primarily) to a few devices I had dotted around the house, especially the Roku SoundBridge M2000 in my bedroom. Previously I had used Apache and mod_mp3 do to simple audio streaming but now I wanted something a little nicer. I read around the multitude of uPnP solutions out there with the one getting the most press being Twonkymedia. Alas that costs $20 (for the Linux server) and I wanted free (because I'm cheap). So not much googling later I came across MediaTomb. Judging from the website it looked like a relatively extensive install procedure but frankly I was surprised. All I needed was:

apt-get install mediatomb

Of course, become root first (su/sudo or just login as root if you can). There's quite a few dependencies which are automatically sorted out by apt (not as good as FreeBSD ports which actually compiles from source but nonetheless good enough).

The database mediatomb uses by default is sqlite but you can use the more heavyweight MySQL database if you want (it's quite easy to do so once you edit the configuration file found in /etc/mediatomb/config.xml

Anyhow the surprising thing is that mediatomb should already be running once apt finishes doing its thing. What you need to do now is find out which port the webserver is running on so you can point your browser there and make it start building the library for streaming. In order to do this all you need to do is:

more /var/log/mediatomb.log

Where you should see something like this:

... stuff ...
2009-02-19 23:04:44    INFO: Configuration check succeeded.
2009-02-19 23:04:44    INFO: Initialized port: 49152
2009-02-19 23:04:44    INFO: Server bound to: 192.168.1.5
2009-02-19 23:04:47    INFO: MediaTomb Web UI can be reached by following this link:
2009-02-19 23:04:47    INFO: http://192.168.1.5:49152/

So now you know where to point Firefox and once you do, have a play around with the interface to add the source of music/videos or whatever.

However slowly you may want to tweak certain things in the configuration file as mentioned before. The best place to start (and finish) is the manual. It's a boring read but you should read it as it does a great job of explaining the attributes. The manual can be found here and the page regarding the configuration file can be found here.

Firewall rules and suchlike could be set so you don't stream out on public IPs and so on.

However the point is to get a basic setup of Mediatomb takes as long as installing the packages in Debian and the time it takes to scan your media directory (which can take a while). As for my SoundBridge, it works a charm.

My next mini-project is to install squid on debian and setup a HTTP proxy. Let's see if that is as easy as this.