Editing Cron The Easy Way

January 10th, 2009
No comments
Whenever I used to try to edit my cron using ‘crontab -e’ I would get the following error.

/bin/sh: /usr/bin/elvis: No such file or directory
crontab: "/usr/bin/elvis" exited with status 127

Now I could try to change my editor settings, but with multiple systems and working with others that shared the same account, this wasn’t the best solution.

To edit the cron without having to rely on the editor settings I first get the cron into a text file to edit.

crontab -l > cron.txt

Then once I’ve made my changes all I had to do was import it back in.

crontab cron.txt

It’s that easy and you even get a copy of the cron.txt for backup if you want to keep it.

cron

Getting Java to work in Firefox on Linux

January 9th, 2009
No comments
If there is one thing that I can never remember, it’s how to get Java to work in Firefox. Last time I checked there was no functional download-and-install-now popup when a site required it. Correct me if I’m wrong though.

You’ll want to make sure you have Java installed in the first place - I prefer to use the full JDK in case someday I get up the courage to tackle programming something in Java. If you’re running Debian, Ubuntu, or another variant, do the following for the jdk:
(change out jdk for jre if you prefer)

apt-get install sun-java5-jdk

Once Java is installed you can link it into your plugin directory for Firefox with the following command (as sudo or root):

cd /usr/lib/mozilla/plugins/
ln -s /usr/lib/jvm/java-1.5.0-sun-*/jre/plugin/i386/ns7/libjavaplugin_oji.so

You’ll want to restart Firefox for the settings to take affect. Test by going to time.gov and browse to your timezone.

Firefox, Java ,

T-Mobile Blackberry Upgrade … Finally!

January 8th, 2009
No comments
A little over a year ago I bought the Blackberry Curve 8320 from T-Mobile and have thoroughly enjoyed it, that is until I saw others with the same phone on different providers and learned that they had much better features. The difference? The OS version; T-Mobile was using OS v.4.2 while the others were using either v.4.3 or v.4.5 which had greater features and allowed video recording.

Well, according to the release date (10/20/2008), T-Mobile now allows you to update to the latest version of the Blackberry OS on their website. I may be a little late on this, but I don’t remember seeing it come across on Slashdot or anything. Either way, if you have a Blackberry Curve with T-Mobile running an older OS, upgrade!

Go to http://www.t-mobile.com/bbupgrade/ and choose your model, put in your phone number, and download the Handheld Software. You’ll probably want to download the latest Desktop Manager too. Oh, and before you do any of this, be sure to backup all you stuff.

Blackberry ,

Add a Datestamp to Digital Photos

January 7th, 2009
No comments
I had a friend of mine that didn’t realize his “datestamp” feature on his digital camera wasn’t turned on when he took some pictures while out of town. He wanted to have that little neon date stamped on all the pictures so he would know when they were taken. Of course you could use Photoshop, but what fun is that? Using command line “mogrify”, a part of ImageMagick I believe, was a great solution.

Here is the basic command for a 3264×2448 image:
mogrify \
-font /usr/share/fonts/truetype/msttcorefonts/arial.ttf \
-pointsize 96 \
-draw "gravity southeast fill orange text 275,150 '10.05.2008'" \
picture.jpg

And even a step further, you could easily start with command above and put it in a loop to recurse directories of photos extracting the actual date the picture was taken from the EXIF info using jhead.

Multimedia , , ,

SSH Private & Public Key Howto

January 6th, 2009
No comments
This is a very simple howto (for Linux/Mac users) on setting up both SSH client side and server side keys. Using private and public keys for ssh, scp, and sftp is great for a series of reasons.

  1. You can give someone your public key to put on their server so you have access. I just did this the other night. As soon as I was done he simply removed my key - no passwords had to be shared.
  2. It allows for better security so you don’t have someone trying to guess passwords or dealing with someone who can’t remember the password and does the “sticky note with password on monitor” trick.
  3. If you choose to not use a passphrase on your keys, you can use it with automated processes that require using scp.
That being said, here are the simple steps.

On the client:
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -q -f ~/.ssh/id_rsa -t rsa
# here you'll be asked to create a passphrase, optionally it can be left blank
scp ~/.ssh/id_rsa.pub yourserver.com:

On the server:
mkdir -p ~/.ssh
chmod 700 ~/.ssh
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
rm -f ~/id_rsa.pub

Also you should note some important settings in your server’s sshd_config file:
PubkeyAuthentication yes            # yes to allow priv/pub key auth
PasswordAuthentication no           # no to ONLY allow priv/pub key auth
ChallengeResponseAuthentication no  # no to ONLY allow priv/pub key auth

If you make any changes to your sshd_config file, you’ll need to restart the SSH server.

OpenSSH , , , ,

Change HTML To Lowercase For Entire Site

January 5th, 2009
3 comments
This is a great script when you need to change HTML code from uppercase to lowercase for an entire site; or at least any given directory on a site. I wrote this one a while back when a friend was in charge of fixing a site that came over from a Windows server to a Linux server. Being that Windows is not case sensitive when it comes to file names, he was going through and manually changing the HTML links <a> to lowercase to match the actual file names. This script did the entire site in a matter of seconds.

WARNING: Please backup your site first or at least use a test copy to make sure there are no issues. Also, it only converts tagged code, that is anything between a < and > so that would include HTML and probably some PHP, ASP, etc, but not any Javascript. That being said, let’s go through the code.

Line 5: Specify the directory you want to recurse.
Line 8: This is where the function is called initially. As it works through the directories it will call itself again and again.
Line 11: Start the sub (function) definition.
Line 12: Get the directory name passed in.
Line 13: Open the directory or fail trying.
Line 14: Loop through all the items in the directory.
Line 15: If it’s not pointing to the current or upper directory, keep going.
Line 16: If it’s a directory then print out what it’s doing then call the function to recurse this directory.
Line 20: It’s a file, not a directory, get the file extension.
Line 21: Make sure it’s one of the files we want to modify - add to or remove from this list if you need to.
Line 22: Print out that it’s parsing the file.
Line 23: Open the file to read it.
Line 25-28: This is where the magic happens. It reads through the file line by line and finds anything inside the <> tags and lowercases it.
Line 30-31: Write the newly changed data back to the file.



That’s it. Please feel free to use this code and modify how you’d like. I’d love to see suggestions for improvement too.

Here is the actual code to copy/paste:
#!/usr/bin/perl
use strict;

# Specify the directory
my $dir = '/home/hallamigo/Desktop/html';

# Call the function
uptolow($dir);

# The function that does the work
sub uptolow {
  my $topdir = shift;
  opendir (DIRH, $topdir) or die "Could not open: $!";
  foreach my $item (readdir DIRH) {
    if ($item ne '.' && $item ne '..') {
      if (-d "$topdir/$item") {
        print "Recursing directory: $topdir/$item\n";
        uptolow("$topdir/$item");
      } else {
        my $ext = substr("$topdir/$item", (rindex("$topdir/$item", '.') + 1));
        if ($ext eq 'htm' || $ext eq 'html' || $ext eq 'php' || $ext eq 'asp') {
          print "Parsing File: $topdir/$item\n";
          open (FILH, "$topdir/$item") or die "Could not open $!";
          my @mod;
          while (my $line = ) {
            $line =~ s/(<.+?>)/\L$1/g;
            push(@mod, $line);
          }
          close FILH;
          open (MODH, ">$topdir/$item") or die "Could not open $!";
          print (MODH @mod);
          close (MODH);
        }
      }
    }
  }
  closedir DIRH;
}

HTML, Perl , ,

DVD to iPod Made Easy

January 3rd, 2009
No comments
Taking one of your DVDs and putting it on your iPod is relatively easy on Debian Linux (Lenny) using the very powerful applications; vobcopy, cat, and ffmpeg. Be prepared to install some new apps if you don’t already have them, but that is really easy with aptitude (apt-get).

First you’ll need to modify your sources.list file to add the debian-multimedia.org repository.
vi /etc/apt/sources.list

and add …
deb http://www.debian-multimedia.org lenny main
deb-src http://www.debian-multimedia.org lenny main

Then run the following:
apt-get update
apt-get install debian-multimedia-keyring
apt-get update
apt-get build-dep ffmpeg
apt-get install build-essential subversion
apt-get install ffmpeg

Finish up with this:
apt-get install libdvdread3 libdvdcss2 vobcopy

Put your DVD in and run the following which will create some .vob files on the same directory level where you ran it:
vobcopy

Combine the .vob files by running:
cat *.vob > full.vob

Now run ffmpeg, tweaking any settings you need to (first remove the comments):
ffmpeg \
-i full.vob \   # input file name
-f mp4 \        # output file format
-r 30 \         # frame rate
-vcodec mpeg4 \ # video codec
-maxrate 1000 \ # maximum video bitrate tolerance
-b 700 \        # video bitrate in kbit/s
-qmin 3 \       # minimum video quantiser scale (VBR)
-qmax 5 \       # maximum video quantiser scale (VBR)
-bufsize 4096 \ # rate control buffer size
-g 300 \        # gop (group of pictures) size
-acodec aac \   # audio codec to use
-ar 44100 \     # audio sampling frequency
-ab 192 \       # audio bitrate
-ac 2 \         # the 2 stereo channels
-s 320x240 \    # output resolution
-aspect 4:3 \   # aspect ratio
~/new.mp4       # filename for output

Where credit is due - the site(s) where I got help and info:
- http://ramblings.narrabilis.com/wp/howto-encode-dvd-video-for-an-ipod-ffmpeg/

Multimedia , , , ,

12 Best Firefox Add-ons

January 2nd, 2009
No comments
For the last couple of years I’ve used different Firefox Add-ons off and on and now have it narrowed down to 12 that I use almost every day.  I’ve got a screenshot attached at the very bottom showing the Add-on Installation window.  My list is in alphabetical order, by the way, not by popularity.

1. DownloadHelper
The easy way to download and convert Web videos from hundreds of YouTube-like sites. This works also for audio and picture galleries.

2. Firebug
Firebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page…

3. Flagfox
Displays a country flag depicting the location of the current website’s server and provides quick access to detailed location and webserver information.

4. Google Reader Watcher
Checks your Google Reader for unread news.

5. Greasemonkey
Allows you to customize the way a webpage displays using small bits of JavaScript. …

6. Organize Status Bar
This extension will enable you to organize your status bar icons. You can now rearrange or remove any item (icon or text) in the Firefox status bar. If your status bar is full and cluttered like mine was, give this a try.

7. ReloadEvery
Reloads web pages every so many seconds or minutes. The function is accessible via the context menu (menu you get when you right click on a web page) or via a drop down menu on the reload button …

8. Screengrab!
Screengrab saves entire webpages as images…

9. SearchStatus
Display the Google PageRank, Alexa rank and Compete ranking anywhere in your browser, along with fast keyword density analyser, keyword/nofollow highlighting, backward/related links, Alexa info and more.

10. ShowIP
Show the IP address(es) of the current page in the status bar. It also allows querying custom information services by IP (right mouse button) and hostname (left mouse button), like whois, netcraft. Additionally you can copy the IP address to the clipboard.

11. Web Developer
Adds a menu and a toolbar with various web developer tools.

12. YSlow
YSlow analyzes web pages and tells you why they’re slow based on Yahoo’s rules for high performance web sites.



Firefox

Easy Apache Basic Authentication

January 1st, 2009
No comments
This is a really handy set of instructions for when you need to restrict access to a website or a directory under a website.  You will need to have access to both the Apache config for your site and the .htaccess file you need to create/modify.

1. In the httpd.conf file put the following for the domain or directory (you can have other options, this is the minimal):
<Directory "/full/path/to/the/directory/to/restrict">
  AllowOverride AuthConfig
  Order deny,allow
  Deny from all
</Directory>

2. In the root of the domain or directory put an .htaccess file with:
AuthType Basic
AuthUserFile /full/path/to/your/new/password/file
AuthName "What You Want The Popup Login Window To Say"
require valid-user
satisfy any

3. Make the password file (you will be prompted to create the password):
/usr/local/apache/bin/htpasswd -c /full/path/to/your/new/password/file username

Apache ,