Jeff Roberts
RHCE #804006066322833
Vim-Fu is now iPhone and Android friendly

Check out the Vim-Fu Store!

Vim-Fu

Realtime tech news

Bulk adding users to Google Apps Premier

My company is making a small jump from Google Apps Standard this morning to the Premier service, but because we are taking the opportunity to change the domain name, we are forced to do a migration.  This is really not a big deal compared to the mail migrations I have done in the past, in fact it’s minor.  I have learned however that mail always needs lots of attention or else it will bite you.

I have to add about sixty users to Gmail, so I worked up a CSV file with username, first, last and temporary password fields the latter of which I pasted randomly generated passwords from PerfectPasswords.  This list will get uploaded to Google to create all the new account and set the temp passwords, but there is no service to then email the old accounts and provide this info to the user.  So I knocked up a little perl script to parse the csv file,  which I called ‘output.csv’ (the output from my awk script that I used to create it) and email each person in the list and give them their credentials. here is the script:

#!/usr/bin/perl
use strict;
use Net::SMTP;

read_file();

exit;

sub read_file
{
    open(FILE, "output.csv") or die("Unable to open file");
    my @data = <FILE>;
    for my $lines (@data) {
        chomp($lines);
        if($lines =~ m/^Username/) {
            next
        }
        my @line = split (',', $lines);
        email_report(@line);
    }
    close(FILE);
}

sub email_report
{
   my ($uname,$first,$last,$passwd) = @_;

   my $email_address = "$uname\@yourdomain.org";
 

   my $smtp = Net::SMTP->new("mailsrv.yourdomain.org",
                       Hello => 'sending.serverdomain.org',
                       Timeout => 60);
   $smtp->mail("from_address\@yourdomain.org");
   $smtp->recipient("$email_address");
   $smtp->to("$email_address");
   $smtp->data;
   $smtp->datasend("From: from_address\@yourdomain.org\n");
   $smtp->datasend("To: $email_address\n");
   $smtp->datasend("Subject: !! Important !! New Email Account Information\n");
   $smtp->datasend("\n");
   $smtp->datasend("New email day is here!\n");
   $smtp->datasend("Your email is going to your new account \"\@newdomain.org\".\n");
   $smtp->datasend("Below is how you log into your account for the first time. Please take time to do this now. \n");
   $smtp->datasend("\n");
   $smtp->datasend("Click the link below\n");
   $smtp->datasend("http://mail.google.com/a/newdomain.org\n");  
   $smtp->datasend("Your Username is: $uname\n");
   $smtp->datasend("Your Temporarry Password is: $passwd\n");
   $smtp->datasend("Your new email address is: $name@newdomain.org\n");
   $smtp->datasend("If the information above is incorrect or you have trouble logging in see a Mail Team member.\n");
   $smtp->dataend;
   $smtp->quit;
}

Great iPhone app for regex testing.

This is a great little utility to have on your iPhone.  It’s called Regexen and it is a tool that allows you to enter some text, and then cook up a regex that will match it.  You can then mail it out to your own email account or a co-worker.  It also has a handy regex cheat sheet.  The app is only $.99 and, in my opinion, well worth it.   http://majestysoftware.com/Regexen.shtml

regexn

Converting from Apache to Nginx

I’ve decided to migrate Vim-Fu.com (WordPress) from Apache to Nginx for a couple of reasons.  The first being that it’s hosted on a virtual slice and needs to be as efficient as possible so I can take the extra resources and hand them over to mysql to improve the site’s performance.  The second is that we are discussing the implementation Nginx at work so I wanted to familiarize myself with it.  What better way than by setting it up and using it.

Googling returned and nice howto from ElasticDog.com, I simply needed to adapt it to Centos.  Here is that process:

  • rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
  • yum install spawn-fcgi
  • yum install nginx
  • /usr/bin/spawn-fcgi -a 127.0.0.1 -u nobody -g nobody -p 9000 -f /usr/bin/php-cgi  <– this needs to run on startup

In the /etc/nginx/nginx.conf file, replace from the ’server’ section of the script to the bottom with:

server {
listen       209.20.67.52:80;  # your server’s public IP address
server_name  www.vim-fu.com;      # your domain name
location / {
root   /var/www/docs/vim-fu.com;  # absolute path to your WordPress installation
#root   /srv/www/;  # absolute path to your WordPress installation
index  index.php index.html index.htm;
# this serves static files that exist without running other rewrite tests
if (-f $request_filename) {
expires 30d;
break;
}
# this sends all non-existing file or directory requests to index.php
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}
}
location ~ \.php$ {
fastcgi_pass   localhost:9000;  # port where FastCGI processes were spawned
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME    /var/www/docs/vim-fu.com$fastcgi_script_name;  # same path as above
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
# required if PHP was built with –enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
}
}
}
server {

listen  your_ip_address:80;  # your server's public IP address
server_name  www.vim-fu.com;      # your domain name

location / {
root   /var/www/vim-fu;  # absolute path to your WordPress installation
index  index.php index.html index.htm;
# this serves static files that exist without running other rewrite tests
if (-f $request_filename) {
expires 30d;
break;
}

# this sends all non-existing file or directory requests to index.php
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}
}

location ~ \.php$ {
fastcgi_pass   localhost:9000;  # port where FastCGI processes were spawned
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME    /var/www/vim-fu$fastcgi_script_name;  # same path as above
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
# required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
}
}
}

I checked to see if php was built with ‘–enable-force-cgi-redirect’ using:

  • php -i | grep force-cgi-redirect

and found that it was enabled at built time.

  • chown -R nginx. /var/www/path_to_site
  • service httpd  stop
  • service nginx start

Can you believe how fast and simple that was?  I didn’t have to make any other changes.  That seems to be the theme of nginx, fast and simple.  There is of course a lot more that nginx can do.

For further reading, check out:

http://nginx.net/

http://wiki.nginx.org/Main

I hope you enjoy setting up and using nginx.

A Scalable DNS scheme for Amazon's EC2 Cloud

We are gearing up for the “next phase” release of our EC2 deployment and I’ve taken the opportunity to re-think the scheme based on my experiences over the last 8 or so months of using EC2. I have come up with something that is FAR better in my [...]

editing remote files

This is a pretty cool little feature.  I am not sure how often it will come into play, but I like it and I thought I would share it.

To edit a file on a remote machine that you have ssh access to, do this:

vim scp://remote_host/filename

Simple as that. Supported protocols are: scp, sftp, ftp and http [...]

using macros in VIM

Repetitive tasks can be annoying and are easily mitigated using the macro functionality in VIM.

For our simple example, let’s count 1 to 10 with each number on a new line.  This will make use of the Auto-increment functionality, discussed in a previous post entitled increment/decrement numbers in VIM, which is CTRL-a and yy, which yanks the [...]

editing a bash command from the CLI using VIM

Ever have a very long shell command that when you run you realize has a mistake right in the [...]

selecting and writing out a portion of a file

Selecting and writing out a portion of a file into another one, or acting on it in some other way is a very handy thing to know how to do in VIM. There are many actions that you can perform, which will save you loads of time, if you just know some basics about [...]

commenting out multiple lines in vim

Visual block mode is a great tool when commenting out a section of code, large or small, all at once.

Look at this section of code from a script I am writing. Let’s say I wanted to comment out everything you see.

I start with my cursor on the “%” and enter visual [...]

bundling versioned ami’s rapidly in Amazon’s ec2

This post will help you better understand the process of “baking” AMI’s and provide you with a script to make the process a trivial [...]