All Posts on Web Development and Programming

Send Email with attachment from the command line in Ubuntu Linux

Apr 9 2011

Sending emails with attachments from the command line in Ubuntu is easily accomplished using a tool called mutt. Mutt allows us to send emails non-interactively. That is, we can invoke mutt from a shell script and it will perform the specified tasks for us with no further intervention needed on our part.

We can also run mutt from a shell (such as bash) or even as a cron job and have it carry out our desired tasks.

Send Email with attachment in Ubuntu - Install mutt

Bash Timestamp - Get Unix timestamp in bash

Apr 4 2011

The current Unix timestamp is a numeric representation of the current date and time. The current timestamp may come in handy when checking when files were last modified or when an event occurred or something of the sort. To get the current Unix timestamp from a bash terminal we may use the following code:

date +%s

If we execute that command in a terminal, we get a really big number which represents the current date and time. We may see output like:


Bash Sleep Command - Pause the execution of a bash script

Apr 2 2011

The bash shell provides an easy way for us to pause the execution of a shell script through the sleep command. The sleep command takes a number as its parameter and then pauses the execution of the shell script for that number of seconds.

Why would we want to pause the execution of a script?

Exclude files from Tar Archive

Mar 29 2011

Tar is a UNIX/Linux utility which is used to compress files for storage in an archive. When we tell tar to compress and create an archive of a directory, it will go ahead and include all the files in that directory.

Sometimes we may want to exclude a particular file from an archive. Tar allows use a convenient option to specify a file or files to exclude when making the archive. The tutorial below shows how we do a tar exclude file operation by using the command line.

Tar Exclude Example - Exclude a single file when using tar

Use Javascript to Highlight Text

Mar 17 2011

Javascript can be used as a handy way to highlight some text for a user when they click on it. This nifty little feature is useful as it saves time for the user since they don't have to do any clicking and dragging.

Use Javascript to highlight text in a textarea

To utilize this feature, we use the javascript onclick event and assign certain actions to it. For example, if we had a textbox with some text in, we would enable automatic highlighting when a user clicked inside of it like so:

<textarea onclick="this.focus();;">

Ubuntu Version from the Command Line

Mar 16 2011

The get the version of Ubuntu or the kernel that is running is quite a simple task when using the command line. Especially on an Ubuntu server where you may only interact with the system through a terminal, it may be easy to lose track of which version of the operating system is running. The version of the kernel which is running may also be obscure since you rarely need that sort of information.

Whatever your interest in knowing these versions, you will find out how to check them below.

How to check Ubuntu version from the command line

Remove 'Preview' button in Drupal 6 comment form

Mar 14 2011

By default in Drupal 6, there is a 'Preview' button in addition to a 'Save' button in the form which allows a user to post a comment. For those of us who think it is silly to have a preview before posting, the good news is that you can remove the button quite simply with a bit of code.

Place the following code in the template.php file which exists in the directory for the theme that you are using. If your theme does not use a template.php file, go ahead and create one.

This code goes in template.php:


Restart MySQL Ubuntu

Mar 11 2011

We may want to restart our MySQL server for a number of reasons. The most likely reason for wanting to restart our MySQL database server is to load new configuration settings. It is a good idea to ensure that no users will be accessing the database server when you are performing the restart just in case the restart fails. Always backup your configuration files before making any changes, as fouled up configuration files are the most likely causes of a failed restart.

How to restart MySQL on Ubuntu

PHP md5 String and File Example

Mar 7 2011

A hash function is useful for checking that something has not been changed. The md5 function is a popular hash function that can be used to generate a hash of a string of text or a file. A hash is useful since you cannot easily determine the input from the hash itself.

You may hash a file and send the hash with the file. The receiver can then rehash the file once they receive it to ensure that the file was not modified during transmission, since a modified file would generate a different hash.

Adding rel="nofollow" to Comments in Drupal 6

Mar 7 2011

By default in Drupal 6, only the Homepage link of a commenter has a rel="nofollow" attribute attached to it. The commenter has free reign on all other <a> tags inside the body of the actual comment. In many cases this is unsuitable.

Spammers like to leave links in comments to transfer Pagerank from your website to theirs. By adding a rel="nofollow" attribute, no Pagerank will be passed to the external page and it will also serve as a deterrent to adding external links to spammy sites in the first place.

Link to this Page