...making Linux just a little more fun!

2-Cent Tips

2-cent Tip: Reading MHT files in Linux

Ben Okopnik [ben at linuxgazette.net]

Fri, 13 Feb 2009 20:08:48 -0500

Just ran across Yet Another Proprietary Format from Micr0s0ft: .mht files. Seems that Internet Explorer saves emails and HTML as an ugly mess that somewhat resembles an email; according to Wikipedia, there's no single standard, and the state of the state is best described as 'sauve qui peut' (which translates, at least in Redmond, as "all your ass are belong to me!") Bleh.

Searching the Web shows that there are a lot of people - the just-converted-to-Linux newbies, particularly - who have loads of these things and don't know what to do with them. Some people recommend Opera (I suppose a couple of hours of Kiri Te Kanawa is good for relieving all kind of stress...); some have had luck with various conversion utilities. I looked at it, and it looked something like a mangled email header, soooo...

I didn't go searching for more than just the one file that I had, but here's what worked fine for opening it:

# Convert line-ends to Unix format
flip -ub file.mht
# Prepend a standard 'From ' mail header to the file
sed -i '1i\'"$(echo From $USER $(date))" file.mht
# You should now be able to open it with your favorite MUA
mutt -f file.mht

It worked fine for me.

* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *

[ Thread continues here (13 messages/18.98kB) ]

2-cent Tip: Quick and Free reminders on your cellphone

Deividson Okopnik [deivid.okop at gmail.com]

Mon, 16 Feb 2009 14:07:49 -0300

Not very Linux related, but this is a nice tip anyway.

If you use a future mail page (like http://www.futureme.org/ ) in conjunct with a email to sms gateway (you can get a list here: http://www.mutube.com/projects/open-email-to-sms/gateway-list/ ), you can send reminders in a free, fast way, directly to your cellphone (and futureme doesnt even need you to signup for an account)

[ Thread continues here (2 messages/2.03kB) ]

2-cent Tip: Converting fonts to images

Ben Okopnik [ben at linuxgazette.net]

Sat, 14 Feb 2009 10:00:18 -0500

On Sat, Feb 14, 2009 at 12:40:15AM -0500, Matt Giwer wrote:

> 	I don't know this qualifies as one but I have used it quite a bit and I 
> have not seen it mentioned elsewhere. Nor have I found it in the docs. 
> This uses the convert function from ImageMagick.
> 	Why? Because many years ago I became addicted to collecting truetype 
> files. There are only a relative few significantly different ones. For 
> the majority they are the same files with a different names. Most of the 
> rest just don't look different enough to matter. I used this to find the 
> one or two gems per thousand.
> 	This works to produce a jpg, or any other image format, of the font. It 
> also works on otf files.

You may not be aware of this, but TrueType files can be viewed with the 'display' program - just as if it were another type of image.

> convert font_name.ttf font_name.ttf.jpg
> 	Generally a filed named ttf-convert
> #!/bin/bash
> while [ $# -gt 0 ];
> do
> convert $1 $1.jpg

This will, of course, fail if the file is called something like 'MS Verdana.ttf' (note the space.) It's always a good idea to double-quote variables used as arguments.

> shift;
> done

Um... wrong tool for the job, I'm afraid. A "while" loop is a state-tester (i.e., checks for true/false and loops); the "for" loop is an iterator, which walks ("iterates") over a list of arguments - which is the exact requirement here.

# Loop over the list of all command-line arguments
for f
	/usr/bin/convert "$f" "$f.jpg"

...but since it's really a one-liner, I would just tend to type things like

for f in *ttf; do convert "$f" "$f.jpg"; done

right on the command line. It's not much harder to remember than yet another script name. :)

* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *

2-cent Tip: Easy way to make security context of two files/directories exactly the same

Mulyadi Santosa [mulyadi.santosa at gmail.com]

Sun, 8 Feb 2009 00:23:52 +0700

If you're administering a Linux system with SELinux policy being enforced, you'll know that most of the times you need to set security context of certain files/directories so it can be properly accessed by daemons or users.

If the task is something like "I create new directory /var/apache/html to put HTML files for my new Apache virtual host", you should make security context of /var/apache/html exactly like /var/www/html (assuming it is the default DocumentRoot of Apache). This command does that for you:

# chcon --reference=/var/www/html /var/apache/html

For additional information, chmod and chown also employ the same option too. e.g:

# chmod --reference=/var/www/html /var/apache/html
makes the access permissions on both directories exactly the same.



2-cent Tip: What was that (masked) script's name?

Ben Okopnik [ben at linuxgazette.net]

Sat, 14 Feb 2009 10:56:06 -0500

Over the years, I've written hundreds of scripts to help me with various tasks. Many of them are still very useful - but whether my memory isn't what it used to be (hmm... I wonder if I can write a script to fix that...), or whether that's just too many things to keep in my head, I've often found myself searching and cursing when I couldn't find the script that I needed and knew I'd already written. Too many scripts!

To deal with this, I've started copying something that I already do elsewhere. When I teach, I give my students a group of scripts that I've made up for each class - and in each of these scripts, I insert an explanatory comment on line 3 (1 is the shebang, while 2 is a comment containing the author credit and a timestamp.) I try to come up with keywords that will be obvious even if I can't remember what I wrote originally. I also include a 'README' script which reports the third line of every file in the directory. There's even a method for ignoring files and adding your own descriptions (do try to avoid the latter, for obvious reasons.)

So, all you need to do is get in the habit of commenting your scripts in clear and obvious ways on the third line. Once you've done that, this little script will save you much time and frustration. Enjoy!

# Created by Ben Okopnik on Sun Dec 10 08:05:39 EST 2005
# Run this script to see the descriptions of all files in this directory
reject='a.out regex.7 access.log'
printf "%-25s%s\n" "regex.7"    "# Henry Spencer's regular expressions"
printf "%-25s%s\n" "access.log" "# Typical Apache log file"
for n in *
    [ -f "$n" -a -z "`echo $reject|grep \"\<$n\>\"`" ] || continue
    printf "%-25s%s\n" "$n" "`/bin/sed -n '3p' \"$n\"`"
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *

Talkback: Discuss this article with The Answer Gang

Copyright © 2009, . Released under the Open Publication License unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 160 of Linux Gazette, March 2009