Search Blog

Author: Chris Hougard
Date: January 1, 2014

Goal:Send email from linux command line using sendmail with a monospaced font

Difficulty: Easy

Prerequisites: Sendmail Installed, Access to a Linux Console

There are many times when formatting an email is not only a nice to have, but necessary to make it useful to the recipient. In this tutorial I will cover how to send an email from linux, using the sendmail program, with fixed font, also known as monospaced font.

This example contains the following files:

mailheader.txt - A text file that contains our static header data, things like the html starting tags, content type, etc

mailbody.txt - A text fiel that contains the body / text of the email we want to send in fixed font / monospace font

mailfooter.txt - A text file that contains our static footer data, basically just there to close out tags for our mailheader.txt, most likely with simple examples this won't be required but since i'm slightly anal about closing my html tags I'll leave it in here even though most things will render the email fine without them. - The shell script that runs our sendmail command and ties all of our formatting files together with our content file


MIME-Version: 1.0
Content-Type: text/html
Content-Disposition: inline
<pre style="font: monospace">

So breaking down mailheader.txt. We are setting the MIME version so that we can set a content type of html and content disposition of inline. Basically what this means is that from here on, the email will be an HTML formatted email, and the content should be inline in the email, as opposed to an attached html file. We then use the

<pre> tag to indicate that the content after this should use html's pre-formatting option which basically makes it so that we can include a simple blurb of text after it and we don't have to worry about our line endings or extra whitespace that html would typically ignore. The other thing we'll note is that we are setting an HTML font styling of monospaced. Now, there are a large number of fonts to choose from but in this example we are going for our typewriter style font so I chose monospace, you could just as easily have made this times new roman or your favorite web font.


Fruit     Number    Color     
Apple     100       Green     
Apple     2000      Red       
Orange    50        Orange

This is our text file that we want to include in a fixed/monospaced font in our email. Typically in my mind this means a fixed font table of some sort but there it certainly works for anything you might want.



And as I said in the file descriptions above, mailfooter.txt isn't the most difficult of files to read. It's just here to close our html tags out from the mailheader.txt file. Additionally, if you were using a multi-boundary email to say include some attachments, you could close off your html section here and start the necessary headers for your attachment.... But I digress.

        echo "From: John Doe <>";
        echo "To:";
        echo "Subject: My Awesome Typewriter Email";
        cat mailheader.txt mailbody.txt mailfooter.txt
) | /usr/sbin/sendmail -t

And now the script that ties them all together. In this file we set the from address, to address, subject, and we tie all of our text files together into one big happy family.

Author: Joe Meyer
Date: January 1, 2014

Goal: Use LDAP and PHP to authenticate with Active Directory

Difficulty: Moderate

Prerequisites: FastCGI and IIS Web Server, PHP LDAP module, Working knowledge of PHP

Many times in enterprise environments you already have an active directory server and all the users you would ever want to access something have an account there. So why go through the trouble of creating yet another authentication system? Why not just leverage those accounts, that way you eliminate another system to remember your password for, use your active directory system to enforce password strength, account lockouts, and all those other built in features that come with active directory.

Some notes about the implementation below: I implemented this on a windows 2012 server with IIS and PHP over FastCGI. Make sure that you have enabled / compiled the LDAP module in php. Where i defined the $adServer variable you can specify either the host name of the domain controller or the ip address. I also included a simple echo in the example to show you how to access objects of the active directory account logging in as well as a var dump so that you can see what the object contains. Please remove these once you know the information you are after.

 * Created by Joe of
if(isset($_POST['username']) && isset($_POST['password'])){

    $adServer = "ldap://";
    $ldap = ldap_connect($adServer);
    $username = $_POST['username'];
    $password = $_POST['password'];

    $ldaprdn = 'mydomain' . "\\" . $username;

    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);

    $bind = @ldap_bind($ldap, $ldaprdn, $password);

    if ($bind) {
        $result = ldap_search($ldap,"dc=MYDOMAIN,dc=COM",$filter);
        $info = ldap_get_entries($ldap, $result);
        for ($i=0; $i<$info["count"]; $i++)
            if($info['count'] > 1)
            echo "<p>You are accessing <strong> ". $info[$i]["sn"][0] .", " . $info[$i]["givenname"][0] ."</strong><br /> (" . $info[$i]["samaccountname"][0] .")</p>\n";
            echo '<pre>';
            echo '</pre>';
            $userDn = $info[$i]["distinguishedname"][0]; 
    } else {
        $msg = "Invalid email address / password";
        echo $msg;

    <form action="#" method="POST">
        <label for="username">Username: </label><input id="username" type="text" name="username" /> 
        <label for="password">Password: </label><input id="password" type="password" name="password" />        <input type="submit" name="submit" value="Submit" />
<?php } ?> 

Author: Joe Meyer
Date: January 1, 2014

Goal: Count Number of Files in a Directory

Difficulty: Easy

Prerequisites: Root Login Access

Often times you want to get an accurate count of the number of files in a specific linux directory/folder. So here's come code to do just that

Note: This will give you the count of files and folders of the directory/folder you are already in.

This will not include hidden files and will be 1 more than the number of files you actually have. So if you have 3 files the output will be 4. Here it goes:

ls -l | wc -l


Now there are times when you really want to see all hidden files and folders in addition to your normal ones.

ls -la | wc -l


We can even take this one step further and do searches on our file information. For example if you wanted to count all files that are read/write for owner only you could use this: (Keeping in mind to subtract 1 from the returned numbers also don't forget to escape your dashes.)

ls -la | grep "\-rw\-\-\-\-\-\-\-"| wc -l


Also, if you want to find all files and folders recursively in a directory you can use the following command:

find DIR_NAME -type f -print| wc -l

Author: Joe Meyer
Date: January 1, 2014

Goal: To remove old / unused linux kernels

Difficulty: Easy

Prerequisites: Root Login Access

Something many linux users will run across is after several times of running their favorite "yum update" command, they are suddenly out of room on the /boot partition of their drive and to make things worse yum update is spewing back error messages saying /boot is out of space every time they try to run. If you're like me perhaps the most annoying thing is that little update icon in the top right hand corner of the screen sitting there saying that it has kernel updates for you and no matter how many times you tell it to update and restart your machine it is still there, but I digress.

Step 1: Find Your Current Kernel Version

To find your current kernel version you can run the following command, but beware if you recently updated your kernel but have not yet restarted or kspliced, your system will show you the kernel that is in use, not necessarily the most recently downloaded. So rule of thumb before kernel updates is make sure you've restarted before removing old versions if possible.


uname -r

Sample Output:


Step 2: List Installed Kernels

Depending on your operating system you can list your installed kernels by using the rpm or dpkg command.

Command for Debian/Ubuntu:

 dpkg --list 'linux-image*'

Sample Output:

| Status=Not/Installed/Config-f/Unpacked/Failed-cfg/Half-inst/t-aWait/T-pend
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name                          Version                       Description
ii  linux-image                           Generic Linux kernel image.
un  linux-image-2.6                                       (no description available)
rc  linux-image-2.6.20-15-generic 2.6.20-15.27                  Linux kernel image for version 2.6.20 on x86/x86_64
ii  linux-image-2.6.20-16-generic 2.6.20-16.32                  Linux kernel image for version 2.6.20 on x86/x86_64
ii  linux-image-2.6.22-14-generic 2.6.22-14.47                  Linux kernel image for version 2.6.22 on x86/x86_64
ii  linux-image-generic                   Generic Linux kernel image

Command for rpm based systems:

 rpm -q kernel

Sample Output:


Step 3: Removing Old Kernels

Finally the actual deleting. Be very careful not to remove the kernel the system is currently running; doing so may result in system problems and will cause you a great deal of headaches. Now that you've been warned pick the kernel from your list of the installed kernels that is not the one you are using and run the appropriate remove command below.

For RHEL / CentOS / Fedora (and any other RPM based system) use:

rpm -e kernel-2.6.12-1.e15

For Debian / Ubuntu systems use:

sudo apt-get remove linux-image-2.6.22-14-generic

Fatal error: Call to a member function getAttribute() on null in /home/exchange/public_html/web/blocks/page_list/templates/exchangecore_blog.php on line 46