Tuesday, July 17, 2007

Mount USB drives on boot

On Fedora Core 7, leaving a USB drive (a simple flash disk) connected doesn't seem to be mounting after reboot even though it's properly listed in the /etc/fstab. I went through a few solutions to this, like this one, but the only one that worked for me was modifying the /etc/rc.sysinit script as I explain below.

I seem to remember creating an entry in the fstab, and allowing the auto option (which is part of the default specification), would make your USB partition mount on boot. The issue with FC7 seems to be that the usb-storage kernel module isn't being loaded when the fstab is first loaded, and that the USB devices aren't initialized yet by /etc/rc.sysinit. This seems to be common with all newer distros, in accordance with the move to udev, hal and other components, which facilitate plug & play user mounting and they don't need them to be available before entering a GUI. This is great for workstations, but I have a "headless" server configuration, therefor I'm not using GNOME to mount anything on-demand, but rather they should be available statically.

After a few days of trial & error, and inspiration from this post, I added the following lines to the end of my /etc/rc.sysinit. Note that changes to this particular file may be removed by system updates (Using yum) as I explain below.
# Try to mount all USB partitions
# This should be moved to `rc.local' and be prepended with a wait
modprobe usb-storage
mount -a

I believe this is the most most robust method, since simply adding the entry to the fstab will allow it to be mounted after the USB devices are initialized. It is preferred to use the /etc/rc.local script to issue this nature of commands (local/custom configuration), but this script seems to be run before the /etc/rc.sysinit script exits, meaning the USB partitions may not yet be available. Commanding the /etc/rc.local script to wait for the /etc/rc.sysinit script to exit may be a solution.

Finally, note that you can guarantee consistency of the partition before mounting it by carefully editing the corresponding fstab line in the normal way, see man 5 fstab for more.

Saturday, July 14, 2007

Label your EXT3 partitions!

If you have removable drives used for backup or portable media, and you're using EXT3 rather than FAT16 (the default format of most USB flash drives), mounting these drives by their Linux device name is ambiguous. For example, I have a hard drive in a Venus DS-3 with a single EXT3 partition on it. The problem is, making the entry in the /etc/fstab file. The /dev/sd[a-z][1-9] designation is not good enough because it changes with the order of the connections during boot-time or plug-in time.

Making labels for each partition to be mounted fixes the problem entirely. To create a label for an ext2/ext3 partition, use the e2label command:
e2label [device] [label]

My exact command was:
e2label /dev/sde1 "Venus1"

Note that I had to find the right drive using 'fdisk' before I knew it was 'sde1'.

The change takes place right away, and then you can put a line in your /etc/fstab like:
LABEL="Venus1"          /media/venus1           ext3    noauto          0 0

And it will run through the drives to find the right label. We've associated the mount location with the partition on the physical device. This is especially important if you're mounting the drives on a server and are not using any automatic mounting facility.

Some recommend to also label the static partitions if you're using only EXT3. If you're using LVM, the groups and volumes are already labeled.

Alternatively, you may use a UUID, obtained from
udevinfo -q env -n /dev/sdd1

Where sdd1 is your USB device, which you can find from
fdisk -l


There is a lot more info you can get with udevinfo but for now, just grab the ID_FS_UUID and you can use it in your /etc/fstab as follows:
UUID=492bc203-de77-40b6-be4b-49e84fee430e /data ext3 auto,defaults 0 0


See http://www.patrickmin.com/linux/tip.php?name=usbkey_mount and
http://floatingsun.net/articles/howtos/howto-usb-automount.html for more.

Narrow-angle Panormas with Hugin


I have a telephoto lens and I wanted to stitch together several pictures of the Baltimore-Washington International airfield. Taking the pictures was just fine, although I hadn't learned how to set the exposure settings yet (see my post on this), and need to do it again on a clear day. What I didn't realize was that there's essentially no 'barrel distortion' with narrow-angle shots.

I found that it's hard for Hugin to figure out the angle of your shots when there's no barrel distortion. It misbehaves if you try to use the same procedure as you would for wide angle panoramas, and gives you completely insane average errors and if you try a preview--it won't be pretty. There are two things you need to do: tell it your horizontal field of view angle, and don't allow barrel distortion optimization. Only use "Positions and View (y,p,r,v)", and check that the barrel distortion stays close to 0.000 for now. This means that your panorama is essentially flat.

I was taking my panorama shots in portrait mode, which meant that my horizontal angle was 75% (the inverse of the aspect ratio 4/3) of the angle in landscape mode. That angle was about 8.10 degrees, and so the angle for each shot was 6.08 degrees. I got my focal length from the EXIF data, 224 mm, but the angle is most important.

Before final optimiztion and stitching, you may want to change the barrel distortion to something between 0.0034 and 0.006. This will add perspective to the panorama. Make sure you still don't run the optimizer for barrel distortion.

Panoramas with the Nikon D-50


This is a panorama I made while learning the following procedure for the Nikon D-50. These same instructions should apply to most Nikon Digital SLR cameras, and can be translated to most other digital cameras. In fact, I find that the huge resolution of my camera doesn't really impact the final product because you want most of the image to fit on your computer monitor, and you're literally multiplying megapixel area each time you take a shot (your canvas gets big quick)--so for close range panoramas, cheap digital cameras are fine as long as you can apply the following instructions to them.

The Nikon CoolPix series, unlike the Nikon D-50, has a Panorama Assist mode. This mode allowed you to take the first shot, which would set up the shutter, aperture and white balance for the rest of the shots. Then the right third of the last image would appear on the left-hand side and be semi-transparent. This allowed you to align landmarks and get good anchors for your stiching. The fixing of the shooting settings was also nice because it meant that the seems wouldn't be visible if you use a good panorama tool (see my post on Hugin).

However, the Nikon D-50 is more professional and didn't include such a mode. No matter! After reading over the manual, which is available on the internet (it was hard to find at Nikon's site, www.nikonusa.com), it was easy to piece together the same process as the 'Panorama Assist' mode.

How to do it:

Get a tripod and make sure it has a level. Set up the tripod and check the level before and after mounting the camera. Loosen the yaw all the way, and tighten the pitch and roll. Without a Tripod, you'll find that your panorama will actually be askew, and picking a level rectangle for cropping will leave you with a lot of wasted image area.

If you're shooting a large up and down angle and have the standard 300mm lens, roll the camera and shoot portrait shots. This means if you don't rotate each shot, you might be stichting tops and bottoms of images in Hugin, which is counterinuitive, but you can rotate the anchor in Hugin later and everything will be fine.

Since we're post-processing the images, you should use 'Fine' mode. You don't have to use 'Raw', and in fact I noticed no real difference between 'Raw' and 'Fine' modes for this application.

The the 'M' mode on the mode dial means 'Manual Mode'. So, you just put the camera into this mode, and the shooting settings (shutter speed and aperture) are fixed.

Note that being in Manual Mode means the camera is not doing anything for you! You'll have to find some angle in your panorama to set the exposure settings until the exposure meter says zero. I favor the angle closest to the sun, but don't let the sun enter the frame. This will leave the dark portions of the panorama underexposed. The exposure meter is inside the viewfinder along the bottom. Rotate the winder on the right-hand side as you normally would to change the shutter speed and find the fastest speed that gets the reticle inside the meter. Then hold down the button on top, next to the power switch, shaped like an iris and rotate the same winder to adjust the aperture. Repeat the process until the reticle in the exposure meter is at zero.

On other thing you'll want to do is find a target at nominal distance to focus (or perform an auto focus) on. Then switch the camera into manual focus mode, since we don't want it to change. Don't accidentally change the focus.

Now you can start snapping away. Pick the most left angle and shoot, then change the yaw of the camera keeping a landmark that was on the right-hand side in the frame. Don't share too much of the yaw angle with the previous frame or you'll take too many pictures. Don't share too little or you won't have enough landmarks (common features) to teach the panorama tool how to stitch them together. You'll get the hang of it.

Finally, load the pictures onto your GNU+Linux workstation (or Windows, bleh) and import the series of shots into Hugin. http://hugin.sourceforge.net/

Hugin Deserves a Hug!


Yes, I know other bloggers have already written in depth about Hugin, but I'd like to share my experience.

First of all, Hugin is just a graphical front-end for already established panorama libraries (which I didn't know existed) called panotools. Before, I would piece together a panorama by hand with The GIMP, but that never made the edges seamless, and never accounted for the lens barrel distortion.

The official page:
http://hugin.sourceforge.net/

They have plenty of tutorials to get you started. The program is not overcomplicated and you can get the hang of it rather quickly (make sure you are following the tutorials). It's just a matter of teaching the panorama tool how the images fit together and how the camera distorts the landscape.

The panorma shown was taken with a Nikon Coolpix 5400 in Panorama Assist mode some time ago. I hadn't been able to see the pictures stitched together because of the intensity of the barrel distortion, but with Hugin, it was a snap!

More process-specific posts on Hugin to come.

Announcing New Bliggity Blog

Assuming that anyone might read this, I just want to make this post to announce that my blog will no longer be strictly GNU+Linux and computer tips. It will still be related to these topics, but posts on 'how to do this' either with a GUI or from the command line are getting too scarce. Note that I will start to use 'labels' (aka 'tags') so that you can still filter out all but a certain topic.

Wednesday, May 16, 2007

Pesky Windows "Thumbs.db" Files

Windows creates a Thumbs.db file whenever it finds an image in a directory. If you are trying to reduce the number of files on your file system, or trying (really hard) to save space, you can issue the following commands as administrator.
locate -r ".*/Thumbs.db" > ~/delme-thumbs.txt

Which queries the mlocate database for the thumbnail files. If you're not running mlocate, you would use the find command here.
cat ~/delme-thumbs.txt | tr \\n \\0 | xargs -0 du -hsc

This will show you how much each file is taking up and include a sum of the total size. Finally, you might want to free these files with the following command:
cat delme-thumbs.txt | tr \\n \\0 | xargs -0 rm

Thursday, March 22, 2007

To Beep or not to Beep

Seems like Linux has done everything to prevent anyone from controlling the I/O devices under /dev, which includes you. I had a simple task, I wanted my "mail-notification" program to beep when I had mail. Under "When new mail arrives:", there was the command "play /path/to/some/sound.aiff" or something... I don't want any process interrupting my sound card because I'm running Fedora Linux, and I don't have JACK or another sound mixer which will mix sounds from multiple processes (maybe one day ALSA will work like this).

So anyway, I tried a million different commands...
echo -ne "\a"
which prints just a bell character, but it's interpretted by mail-notification (or nothing) and is lost--not sounded on the system beeper.

I tried a C program by Johnathan Nightingale, beep, which I had lying around, but it fails because the kernel doesn't like it touching the devices.

Finally, I thought "hmm, beep.c is just writing to /dev/console, why can't I?" and I tried
echo -ne "\a" > /dev/console
And it worked! It's not the same beep as Thunderbird/xterm/emacs, but it's fine with me!

Sunday, March 18, 2007

Executing a command on multiple files with FIND

Okay, so apparently, the FIND command is so powerful that you can even tell it what to do with the files when it finds them. I always used to find multiple files, translate newline characters to null characters, then pass each argument to XARGS as in:
find ./ -regex ".*\.mp3" | tr \\n \\0 | xargs -0 -n 1 md5sum > mp3checksums.md5

But, you can also say:
find ./ -regex ".*\.mp3" -exec md5sum {} \; > mp3checksums.md5

Where, the {} implies to insert an individual argument into that part of the exec string, and the semicolon (escaped so it's not picked up by BASH) ends the -exec agrument.

Tuesday, March 13, 2007

Computer Internal Dust Solutions


It seems like opening up my computer (or multiple in my case) and blowing it out every month is releasing too much dust back into the air, and all those particles that were stuck in there can wreak havoc upon your moving parts (fans). Assuming you operate electronic devices which have ventilation fans indoors, try the following.

Get a HEPA filter and run it, at least on its lowest setting, all the time.
The electricity it takes to run such filters is completely eclipsed by how much dust they remove from the indoor air and prevent those particles from being stirred up again. It's better for human breathing, and better for devices with moving parts. Also, if the filter circulates the air, your components might run cooler.

Install low-impedance dust filters in front of your computer's ventilation intakes.

Many computer cases are already shipping with single-layer plastic mesh filters which will stop most huge dust particles (the ones you can see anyway). I decided to give it a shot and installed some extra dust filters on the intakes of two computers. One computer had side ports which were completely open (no, fan, just big holes). NOTE: If you have filters installed, air will follow the path of least impedance, so either block or put filters over all air passageways that flow into the case. Don't put filters on exhaust ports (ports which blow out).
I decided to use WEB Vent Filters, but these have a few drawbacks: they have fibers which come loose, and are higher impedance than the coarse foam. Coarse foam like that in SHOP*VAC Foam Sleeves is preferred for low impedance of air flow, but doesn't offer good filtering of smaller particles. Both are readily available at the local hardware store.



I put WEB Vent Filters on the outside of the case (so they wouldn't get sucked into the fan) for one, and in between the case and the air duct for the other. On the other computer, I took the front panel off, and installed the filters over the intake fans, but under the outer cover. The only concern I have now is cleaning these. I'm hoping that after the one-to-two month interval, I can vacuum the filters externally to clear large debris back out through the intake, and then the next interval I can remove them and wash them under water.


WARNING: Remember, the foam should be low impedance! Any dust filter you install over a ventilation port or fan will impede the flow of air through your device. Fans will spin a little faster, but air flow will be slower. Make sure this doesn't cause any heat issues, and either remove the filter or install more fans if necessary. Inevitably, over time the filters will become clogged and become further impeding, and will require replacement or washing.

Vacuum and dust often.
I know, this is common sense, but I've seen people who just have a million Duster cans and they blow out their computer whenever it starts to make noise. Grinding noises are a very bad sign--this means that something is on or around the fan's journal (which usually has ball bearings), and the fan will most likely fail if not cleaned. Oiling the fan's journals using three-in-one motor oil can help, but the best bet is to keep the fans free from particles beforehand, and replace them when things start to go awry. Rule of thumb: if you have to clean it out more than once every one to two months, you have a dust problem. Also, blowing the dust around can cause a fan assembly to become dirty.

Finally, keeping these computer systems away from sources of dust is a good idea. Major sources of dust include laundry, bedding, and animals and humans.

Sunday, February 04, 2007

Shell Script to Parse Command Line Arguments

Problem: I needed a script that took just file names and translated large JPEG's into smaller or thumbnail images. The problem was the convert command, part of ImageMagick, needs the specific output file name.

Solution: The following script.
#!/bin/bash

if [ ! -d Thumbs ] ; then
mkdir Thumbs;
fi

while [ $# -ge 1 ]; do
TARGET=`echo -n "$1" | sed "s/.jpg/t.png/" | sed "s/.JPG/T.PNG/" | sed "s/.jpeg/t.png/" | sed "s/.JPEG/T.PNG/"`;
if [ -e $TARGET ] ; then
echo "Refusing to overwrite $TARGET. ";
else
echo -n "Converting $1 to Thumbs/$TARGET: ";
convert $1 -resize 128x128 Thumbs/$TARGET;

if [ $? -eq 0 ]
then
echo "OK."
else
echo "ERROR: $?"
fi

fi

shift

done
exit 0

Wednesday, December 27, 2006

Bragging Rights

I put a new computer together, so I could have better performance than my previous rig. I wanted a powerful but quiet workstation. I just didn't feel like installing Windows--I've never felt so dissuaded from installing Windows. It just seemed like an unnecessary hassle. I just wanted to have just Fedora Linux on the machine.

In sort of an aimless manner, I ended up having a software RAID partition with an 899GB capacity. I don't know if I'll keep this configuration, but it's very fast and I can't imagine running out of space. I just hope it's not drawing too much power. I was pretty floored by the following responses from Linux:

/proc/cpuinfo:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz
stepping : 6
cpu MHz : 1596.000
cache size : 4096 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
bogomips : 4811.97

processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz
stepping : 6
cpu MHz : 1596.000
cache size : 4096 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
bogomips : 4805.23

Now, my Pentium 4 3.2GHz processor gave me 6,400 bogomips for each CPU, but we all know that only approximately 6,400 operations per second can occur. In other words, the second CPU is virtual and only gets work done when the 31-stage Pentium 4 pipeline would otherwise be empty. These two 4,800 bogomips readings can occur simultaneously, allowing approximately 9,600 bogomips for the whole system.

/proc/meminfo:
MemTotal: 2074924 kB
MemFree: 1084092 kB
Buffers: 32624 kB
Cached: 673980 kB
SwapCached: 0 kB
Active: 481828 kB
Inactive: 454244 kB
HighTotal: 1179264 kB
HighFree: 264560 kB
LowTotal: 895660 kB
LowFree: 819532 kB
SwapTotal: 4095992 kB
SwapFree: 4095992 kB
Dirty: 42252 kB
Writeback: 0 kB
AnonPages: 229628 kB
Mapped: 55352 kB
Slab: 35120 kB
PageTables: 4552 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
CommitLimit: 5133452 kB
Committed_AS: 602780 kB
VmallocTotal: 114680 kB
VmallocUsed: 7012 kB
VmallocChunk: 107160 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
Hugepagesize: 4096 kB
Filesystem Size Used Avail Use% Mounted on
/dev/md2 899G 3.2G 849G 1% /
/dev/md0 99M 10M 84M 11% /boot
tmpfs 1014M 0 1014M 0% /dev/shm
192.168.0.5:/home 360G 249G 94G 73% /home
/dev/hde 3.3G 3.3G 0 100% /media/FC_6 i386 DVD

There are two 500GB SATA 3.0GB/s Seagates!

[root@localhost ryan]# /sbin/hdparm -t /dev/md2

/dev/md2:
Timing buffered disk reads: 426 MB in 3.01 seconds = 141.61 MB/sec
[root@localhost ryan]# /sbin/hdparm -t /dev/md2 ; /sbin/hdparm -t
/dev/md2; /sbin/hdparm -t /dev/md2

/dev/md2:
Timing buffered disk reads: 434 MB in 3.01 seconds = 144.34 MB/sec

/dev/md2:
Timing buffered disk reads: 434 MB in 3.00 seconds = 144.60 MB/sec

/dev/md2:
Timing buffered disk reads: 434 MB in 3.01 seconds = 144.26 MB/sec
[root@localhost ryan]# /sbin/hdparm -T /dev/md2 ; /sbin/hdparm -T
/dev/md2; /sbin/hdparm -T /dev/md2

/dev/md2:
Timing cached reads: 5120 MB in 2.00 seconds = 2565.42 MB/sec

/dev/md2:
Timing cached reads: 5152 MB in 2.00 seconds = 2580.52 MB/sec

/dev/md2:
Timing cached reads: 5060 MB in 2.00 seconds = 2533.59 MB/sec

Tuesday, December 12, 2006

Nightly Backup Script

If you're working on a small project, you might want to do a simple nightly backup. The following Bash Shell Script, when copied into your /etc/cron.daily/ directory will do the trick. You might have to allow read access for 'other' users for everything you want to back up. It worked without changing that for me.

Obviously, you'll have to change the file and directories. This is just an example.

[ryan@a564n cmpe646]$ cat cmpe646_backup.sh
#!/bin/sh

date=$(date +%s)

tar -cf /home/cmpe646/cmpe646_project_backup_$date.tar /home/cmpe646/*/*.h* /home/cmpe646/*/*.c* /home/cmpe646/*/*.bench*
bzip2 /home/cmpe646/cmpe646_project_backup_$date.tar

exit 0

Blowing out Fans

I took some highly compressed air and blew out a small processor fan (VIA EPIA) because it seemed to be making noise. It started to make more noise after I blew it out. So at first, I thought maybe I was using too much air pressure, but then I remembered that tiny fans usually make the most noise when compared to much larger fans. Later, I went and noticed that the fan was spinning a lot faster after I blew it out. Something I didn't expect to see. Then, I noticed a downward trend over the last half of a year since the fan was put into commission.

What I get from these pictures is that the fan is now spinning faster like it was half a year ago and the processor also started running cooler after I blew out the fan.





The conclusion: The failure mode of computer case fans is to develop (physical and electrical) resistance and spin slower and slower. They should be kept clean to prolong the life of the fan and the components they cool, but don't use too much pressure--you don't want to break the assembly.

If you're using compressed air -- you can use about 80-100 PSI, but don't use anything bigger than a Sports Ball Inflator or you'll have too much air velocity. Also, if you don't have a filter or anything on your compressor, you have to be careful about debris! Don't hold the air canister upside down or anything that might stir up dust or debris inside the tank. For most people, it's probably best to go to the store and get a can of "air" for your exact purpose.

Sunday, November 19, 2006

Comparison of 20.1" LCD Monitors


I wanted to know which display would be better for desktop computing: a normal 1600x1200 pixel display or a widescreen 1680x1050 pixel (HDTV) display. The widescreen, would be more efficient for movies. I remember doing this once before, so I decided to write it out this time. To simplify my analysis, I chose to consider only 20.1" diagonal viewing areas, with the aforementioned resolutions.

For the widescreen, I calculate the display is 17" by 10.6", giving a viewing area of 181.6 square inches. For the 4:3 ratio display, I got 16" by 12" inches, and a viewing area of 193.9 square inches. This is a 6.7% bigger display area for the 4:3 ratio display. More generally, if the diagonal length is fixed, a square maximizes the area of a rectangle.

To compare the resolutions, the widescreen gives 1.76 megapixels, and the 4:3 ratio gives 1.92 megapixels. This is a 9.1% increase in pixel count for the 4:3 ratio display.

In conclusion, you win with the 1600x1200 20.1" non-widescreen display in terms of specifications, but they are generally more expensive (partly due to TFT manufacturing realities) but more compatible with video games (until recently). The wide screen, however, might be a more natural design because of our rectangular viewing perspectives.

Friday, November 03, 2006

Fedora Core 5 + IMAP Server + SquirrelMail

The next best thing, because sharing the Mozilla Thunderbird Storage folder is giving me problems when I change networks, is to have an IMAP server that Thunderbird can store/retrieve messages with.

The mail from the Internet accounts could be copied to the IMAP server using Thunderbird, even if a delivery system (POP/SMTP) is not in place (for mail to get there otherwise). I installed SquirrelMail and tested this capability with Thunderbird already. I closed down sendmail, installed and started postfix. I set up the Cyrus IMAP, which was the hardest part of the IMAP/SquirrelMail setup.

The tutorials I found to help do this on Fedora Core 5 are:

http://cyrusimap.web.cmu.edu/imapd/install.html
http://nakedape.cc/info/Cyrus-IMAP-HOWTO/quickstart-fedora.html
http://www.howtoforge.com/perfect_setup_fedora_core_5

The last one shows how to set up SMTP, as does the one from Cyrus itself. I'm still trying to figure out if I can have my own SMTP and use my IP Address (or its alias) as a domain for sending mail to.

Even if I can't, I think that having the IMAP server in place, just for storing mail, would be a big help as the mail would be accessible from anywhere (even using SquirrelMail).

Thursday, November 02, 2006

PHP Gas Mileage Application

Here's a little something I wrote out of necessity and decided not to stop before it was completed. I'm pretty proud of it and am surprised how easy PHP was to learn. It basically helps me keep track of my gas mileage over the web so I can throw the receipt out faster, and don't have to carry a spreadsheet around. The following is from the program itself:

This program is a gas mileage database and analyzer written in PHP. It is self-contained (has a single source code file). It stores data in a simple text file in HTTP-query format. It allows users to add new records, and add new data files for different vehicles. It creates a backup before a new record is added. It also implements password protection before users can add refueling records.

Source Code:
Source Code
See it in action

Saturday, October 28, 2006

Simple Web File Upload Form

I put the following form and post processing files together from a manual on PHP. The HTML could really be embedded in the PHP file, but this might be better if you only want one copy of the PHP code on the system. Modify both to fit your environment and make sure the PHP file is executable.




Example .HEADER.html


Example getfile.php


This code is derived from a few examples.

Web File Search CGI Program for Linux

So you can install Fedora, and choose the Web Server package. If you are running any kind of file server, you will probably want to find a file over the web. This script allows users to search the mlocate database which is usually compiled by your Linux installation every night. It's a fast database which circumvents searching the filesystem manually. I had to write it, so I extend my source code to everyone in hopes that it will help someone.

It has some thought put into security. The results are displayed as links to facilitate viewing/downloading the located file. It should be used to search one part of the file system. In my case, the public area is /srv/. This part of the filesystem should be linked into the Apache document root via
ln -s /srv /var/www/html/srv
to allow the users access to the files with your HTTP server.

Following is the Perl-CGI code. Name it locate.cgi and it should go in your cgi-bin directory. Don't forget to chmod 755 the file so it's executable. Because of technical limitations of Blogger, I can't paste the Perl-CGI code here--please follow the following link:

http://www.cs.umbc.edu/~rhelins1/getfile.php?id=26

Thursday, October 26, 2006

Using the Same Thunderbird Storage Folder on Windows and Linux

Today I finally solved the problem of having multiple e-mail clients and multiple storage folders. First I used an IMAP account I have access to in order to move all the old e-mail I have on multiple computers onto the Thunderbird "Local Folders" in Linux on my server. This is as easy as copying all the messages in one Inbox to the Inbox on the IMAP account, and then on the other computer moving the messages out of the Inbox on the IMAP account to the local Inbox account. It's not the fastest, but it's the most compatible as Thunderbird doesn't support much importing from other e-mail storage folders.

So once I had everything on the "Local Folders" account in Thunderbird on Linux, I changed the Local Message Storage directory on Windows (not on the Server) to the storage directory in my home folder on my Linux server via a drive-mapped Samba share:
Y:\.thunderbird\ayrxordj.default\Mail\Local Folders
This can be found by going to Tools->Account Settings->Local Folders. Click Browse. You'll have to have "Show Hidden Files" ON to locate your Local Folders path with the GUI. You also need to make sure that all your e-mail accounts you have are set up to store the mail in the "Local Folders" rather than an individual folder for that account.
After some testing with no networking on the Windows computer, if the client doesn't have accesss to the network drive, you just get nothing under "Local Folders". In other words, it doesn't crash or anything.

So what does this mean? If I download a message on my Windows Thunderbird client, it is exactly like downloading it on the Linux Thunderbird client. It is the same for the Linux client (vice-versa). It also means that now I can have "Delete message from POP after download" set to "Yes" on both clients and avoid downloading e-mail that I've already seen.

Issues I can imagine running into include having both clients open simultaneously and possible Operating System dissimilarities in the implementation of Thunderbird. Also, it took a long time to open the gigantic storage folder the first time over the network, but cleaning up the 2-3 thousand messages and perhaps "compacting" the folders should help. The other issue is, since I merged the two clients, there are several duplicate e-mails, but there is an extension to find & delete duplicate messages which has already solved this problem for me. I removed all the duplicates (leaving me with only roughly two thirds of the messages, because this merge was so large) and compacting the folders did solve the long-to-load problem.

Now I can load up Thunderbird on Windows or Linux using the same "Local Folders" storage directory. Finally, no more getting on different computers/clients to find different mail.


There are still issues with using this technique. If you have a laptop or are losing connectivity, Windows will let you know that "Delayed Writing" failed. Also, a solution like having IMAP storage would be much more network-friendly in terms of bandwidth. See my post on setting up Cyrus IMAPD