Convert text files from DOS to UNIX and vice versa.

Here are few recipes to convert DOS text files to UNIX.

How do you know whether you have a DOS text file or a UNIX text file? A line feed and a carriage return terminate the DOS text files lines. UNIX uses only a line feed character. By using the Unix command file you can figure out which type of file you are dealing with.
$ file dosfile.txt 
dosfile.txt: ASCII text, with CRLF line terminators
$ file unixfile.txt 
unixfile.txt: ASCII text

$ file dosfile.txt
dosfile.txt: ASCII text, with CRLF line terminators
$ file unixfile.txt
unixfile.txt: ASCII text

To convert files back and forth from one format to another you have several options. A few of them are showed here.
 
Posted on Feb 22, 2009 by: Fred Cirera @ 14:03 Leave a comment Comments: 0

X11 on MacOS X and CMD-W

The most annoying thing with X11 on Mac is the shortcut CMD-W, especially when you are an Emacs user. On Emacs, CMD-W or META-W is the shortcut to put your selection into the cut buffer. But on Mac this is also the shortcut to close the window. This means that every time you type META-W on Emacs your Emacs window closes and you loose everything you are doing.

This recipe will explain how to remove the annoying CMD-W shortcut on X11.

 
Posted on Feb 21, 2009 by: Fred Cirera @ 15:22 Leave a comment Comments: 1

Twitter Weather station

Create your own weather station on Twitter.

With these few simple steps and this following code, you can have the weather information from where live automatically updated to you twitter account. These following steps are for a Unix/Linux/Mac environment but I am sure they can easily adapted on Windows.
 
Posted on Feb 17, 2009 by: Fred Cirera @ 22:35 Leave a comment Comments: 2

Print messages on a mini LCD.

At work, I manage a cluster of several hundred nodes. All those nodes are equipped with a little LCD display, like to one showed in the picture on the right. Until now, these displays were only displaying the name of the cluster vendor at boot, and the node name when the machine was up an running. To put these neat little displays to better use, I wrote a Python program named lcd.py, which prints more useful information.

When started, lcd.py burns into the MVRAM of the display the name of the company I am working for and the name of the node, which is in fact the position of the node in the rack. This helps me find which node is which when I take several of them out of the rack for maintenance. I just power the machine for a few seconds to read its name and position on the racks on the LCD display .

Then, the daemon goes into an infinite loop to probe the disk temperature using the S.M.A.R.T information provided by the disk. This information is then displayed on the second line of the LCD display. A quick look at the display and I know if something is wrong with the disk or the machine. Of course this is not the only monitoring system used to watch the system but every little detail helps. And it is fun to use these little displays.

The program also pings the “master node” to see if there are any network problems. If the “master node” cannot be reached, the program turns off the LCD display backlight. A quick glance at the entire rack and you know which node is in trouble.

For more information on these LCD display you can download the manual.

Download the entire source code

 
Posted on Feb 13, 2009 by: Fred Cirera @ 22:18 Leave a comment Comments: 0

Heartbeat code for cluster environment

Working in a cluster environment, I often need to check in my Python programs, if some of the nodes of my cluster are dead or live. To do so I have in my Python toolbox, a class called Heartbeat. This is a simple heartbeat class does a ping on the cluster node, and return True, or false depending on the health of the targeted node. This class implement a stripped down version of ping. It send a ICMP_ECHO_REQUEST packet and wait for the answer.

To use this call I call the constructor with the node name, or IP address, followed by the number of seconds between heartbeats. Then every time I need to check in my program if the node is still alive, I call the method is_alive() which returns a Boolean.
 
Posted on Jan 31, 2009 by: Fred Cirera @ 23:46 Leave a comment Comments: 0

Intel Core i7 vs Core 2 Quad

Insidehw ran a bechmark test between an Intel Core 2 Quad and an Intel Core i7. This test shows that the Core i7 is slightly faster than the Core 2 Quad, but not enough to justify the price difference between the two.

If you are planing to upgrade your machine from a Core 2 to a Core i7, you also have to add the price of a new motherboard and new memory. Which makes the upgrade way too expensive for a not that noticeable performance gain.

Read the full benchmark results

 
Posted on Jan 01, 2009 by: Fred Cirera @ 17:02 Leave a comment Comments: 1

Risk-Taking Lifelong Learning Tree Hugger

I took the 43 Things Personality Quiz and found out I'm a

Risk-Taking Lifelong Learning Tree Hugger

0% of the 18123 people who have taken this quiz are like me.

 
Posted on Jan 01, 2009 by: Fred Cirera @ 16:35 Leave a comment Comments: 0

Vacation message with exim

I don't really understand why people love so mush auto-responders, especially business people. These messages add a considerable amount of useless noise in our mailboxes. Even though I dislike those emails, it doesn't prevent companies or friends I am hosting on my servers to request them.

One of those companies is closing during the holidays. They wanted to have a vacation message sent whenever someone tried to contact them during this period.

They wanted to have a single vacation message for the entire company instead of asking each employee to set his or her own vacation message for each account.

Here is the solution I have used to do this.

Router

virtual_vacation:
  domains = +virt_domains
  driver = accept
  require_files = /space/hosting/${domain}/vacation.msg
  transport = virtual_vacation_trans
  condition =  ${if or { \
                {match {$h_precedence:} {(?i)junk|bulk|list}} \
                {eq {$sender_address} {}} \
                } {no} {yes}}
  # do not reply to errors or bounces or lists
  senders = ! ^.*-request@.*: ! ^bounce-.*@.*: ! ^.*-bounce@.*: ! ^owner-.*@.*:\
            ! ^postmaster@.*: ! ^webmaster@.*: ! ^listmaster@.*: ! ^mailer-daemon@.*:\
            ! ^root@.*: ! ^abuse@.*
  unseen
  no_verify

virtual_vacation:
domains = +virt_domains
driver = accept
require_files = /space/hosting/${domain}/vacation.msg
transport = virtual_vacation_trans
condition = ${if or { \
{match {$h_precedence:} {(?i)junk|bulk|list}} \
{eq {$sender_address} {}} \
} {no} {yes}}
# do not reply to errors or bounces or lists
senders = ! ^.*-request@.*: ! ^bounce-.*@.*: ! ^.*-bounce@.*: ! ^owner-.*@.*:\
! ^postmaster@.*: ! ^webmaster@.*: ! ^listmaster@.*: ! ^mailer-daemon@.*:\
! ^root@.*: ! ^abuse@.*
unseen
no_verify


The router checks if the file message.msg exists in the home for that domain.
The router also tries to determine if the mail is coming from a mailing list or if it was auto-generatd. We don't want to send the vacation message to these addresses.

Transport

virtual_vacation_trans:
  driver = autoreply
  to = ${sender_address}
  from = "do_not_reply@${domain}"
  file = /space/hosting/${domain}/vacation.msg
  once = /var/tmp/vacation_${domain}.db
  once_repeat = 7d
  subject = "Re: Away for holidays / En vacances - ${local_part}@${domain}"

virtual_vacation_trans:
driver = autoreply
to = ${sender_address}
from = "do_not_reply@${domain}"
file = /space/hosting/${domain}/vacation.msg
once = /var/tmp/vacation_${domain}.db
once_repeat = 7d
subject = "Re: Away for holidays / En vacances - ${local_part}@${domain}"


The transport is pretty straightforward. It sets the to, from, and subject as well as the content of the mail extracted from the file vacation.msg. The email addresses of the senders are kept into the file vacation${domain}.db, in order to send the vacation message only once a week. Determined by once_repeat = 7d.
 
Posted on Dec 24, 2008 by: Fred Cirera @ 15:58 Leave a comment Comments: 0

Fortune cookies on Twitter (part 2)

A couple of day ago I posted an article Unix fortune cookies on twitter containing the source code for a Python script allowing you to post Unix type fortune cookies to your Twitter account.

In that code, I was using a package called fortune developed by Brian M. Clapper. The problem is that this package does not allow you to use the existing fortunes files provided by your operating system. The .dat file used by that package are not compatible with the .dat file of your operating system. Also the actual version of the package contains a bug and the creation of the .dat file doesn't work. That's why I developed the following get_fortune() function, which can use the operating system's fortunes files.
 
Posted on Dec 07, 2008 by: Fred Cirera @ 14:00 Leave a comment Comments: 0

Unix fortune cookies on Twitter.

I just wrote a new script called twfortune. It chooses a random fortune, as the fortune(8) program in the BSD-games package does, and send it to your twitter account as a message of the day (motd)
You can download the complete script and a sample fortunes file from this link.
http://velvnet.com/c

 
Posted on Dec 03, 2008 by: Fred Cirera @ 15:03 Leave a comment Comments: 3