Ahoy there! This is my personal blog which I use as my memory extension and a medium to share stuff that could be useful to others.

Application Software Archives

Sendmail is slow

Problem:

The sendmail service takes a while (more than a minute) to start and emails sent via sendmail take a couple of minutes to get delivered:

 

Background & Analysis:

Sendmail uses DNS for the following:

  • At startup, to obtain the canonical name for the local host.
  • To obtain the canonical name of a remote host that connects to the local host.
  • To obtain the address of the the SMTP Relay to which sendmail connects.
  • When sendmail expands $[ and $] in the RHS of a rule.

Refer this article for more details.

Solution:

STEP 1: Ensure that the local host’s canonical name may be looked up by adding the following as the first entry in /etc/hosts:

127.0.0.1       localhost.localdomain <hostname>

where, <hostname> should be replaced by the local host’s hostname.

Restart the sendmail service as shown below:

 sudo service sendmail restart 

Implementation of this step enabled my sendmail process start up very quickly.

 

STEP 2: Ensure that the SMTP Mail Relay is configured to not look up DNS by surrounding the Mail Relay’s address by square brackets in /etc/mail/sendmail.cf as shown in the example below:

DS[10.1.1.10]

Restart the sendmail service as shown below:

 sudo service sendmail restart 

Implementation of this step enabled my sendmail process to deliver emails quickly.

 

Root Cause:

The sendmail process takes a while to do lookups in DNS.

 

(1) The solution above describes a successful problem-solving experience and may not be applicable to other problems with similar symptoms.

(2) Your rating of this post will be much appreciated as it gives me and others who read this article, an indication of whether this solution has worked for people other than me. Also, feel free to leave comments.

 

VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

Logrotate: High CPU utilization and failure

Problem:

The logrotate process caused high CPU utilization, ran for about 5-6 hours and finally exited with a non-zero (failure) exit code.

Background & Analysis:

Observed this problem on one of our RHEL 3 hosts. A new daily job was added and this job specified log rotation for all files in a directory (rather than a file or specific patterns to match files) and used the compress option. Consequently, logrotate compressed files that were already compressed and so on and files in the directory started having very long filenames (e.g. test.dmp.gz.gz.1.gz.1.gz…) and a huge number of files were present in the directory, making logrotate’s job more and more difficult, thereby causing logrotate to consume high CPU (system cpu utilization %) and take longer to complete. Also, logrotate’s state file (/var/lib/logrotate.status) ended up being about 58 MB.

Solution:

  • Modify the daily job to rotate only files matching a specific pattern (in my case, I removed the daily job as it was redundant. The files were created with timestamp prefixes and so rotation wasn’t required).
  • Remove logrotate’s state file (/var/lib/logrotate.status). When done, logrotate will generate a new state file.

NOTE: The removal of logrotate’s state file is akin to running logrotate for the first time. So, you can modify the dates in the state file to reflect the previous day or the previous week before running a daily or weekly job to ensure logrotate rotates the files on its first run. ALternatively, use the logrotate –f option.

Root Cause:

Improper configuration of logrotate for a daily job.

(1) The solution above describes a successful problem-solving experience and may not be applicable to other problems with similar symptoms.

(2) Your rating of this post will be much appreciated as it gives me and others who read this article, an indication of whether this solution has worked for people other than me. Also, feel free to leave comments.

 

VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)

New Page Notification In Mediawiki

In trying to make my team aware of what’s in our team’s wiki (based on Mediawiki), I wanted a simple notification to go out to the team daily listing the new wiki pages created on the previous day. This may be achieved with a simple shell script that queries the Mediawiki recentchanges table.

STEP 1: Deploy Shell Script

The following script queries the recentchanges table and fetches data for pages created (rc_type = 1) the previous day in the Main namespace (rc_namespace = 0).

#!/bin/bash
# Author         :       Cybergavin (http://www.cybergav.in)
# Date Created   :       31st March 2012
# Description    :       This simple script queries the Wiki database and sends a notification to specific users regarding page creation. Reminds users about the existence of the wiki and what's in there.
#####################################################################################
#
# Variables
#
EMAIL_RECIPIENTS="wikiusers@abc.com"
REPORT_DATE=$(date '+%Y%m%d' --date="yesterday")
REPORT_DATE_FORMAIL=$(date '+%d-%b-%Y' --date="yesterday")
WIKI_BASEURL="http://wiki.abc.com/wiki/index.php/"
#
# Functions
#
getDBdata()
{
mysql -u wiki -p'xxxxx' --skip-column-names wiki <<EOSQL
connect wiki;
select rc_title, rc_user_text from recentchanges
where rc_timestamp like '$REPORT_DATE%'
and rc_type = 1
and rc_namespace=0;
quit
EOSQL
}
#
# Main
#
mail -s "Tech Ops Wiki : New Page Notification For $REPORT_DATE_FORMAIL" $EMAIL_RECIPIENTS <<EOMAIL
Hi

Given below are Pages created on the ABC Wiki ( http://wiki.abc.com ) yesterday ($REPORT_DATE_FORMAIL) along with their authors:

`getDBdata | awk -v a="$WIKI_BASEURL" '{printf "%-70s %s %s\n", a$1,"-", $2}'`

EOMAIL
#
##################################### T H E     E N D ###############################

NOTE:
(1) You must change certain variables and the body of the email as per your requirements.
(2) If your wiki isn’t updated with new pages very often, you may send this notification weekly. To do so, simply replace “yesterday” by “last week” on lines 11 and 12 and replace “where rc_timestamp like ‘$REPORT_DATE%'” by “where rc_timestamp > $REPORT_DATE0000”

STEP 2: Cron the Shell Script

Set up a cron job to send a daily notification. The example below executes the script daily at 9 AM.

0 9 * * * /opt/support/wikiPCnotify.sh > /opt/support/wikiPCnotify.out 2> /opt/support/wikiPCnotify.err 
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

How to Install PHP with FreeTDS on Linux

There are PHP applications which use MSSQL as the back-end database and such applications require FreeTDS to enable PHP code interface with MSSQL. This article describes how to install PHP and FreeTDS on Linux hosts.

To compile or not?: Typically, it is recommended to use package managers like yum to install software on Linux platforms. Using package managers facilitates installation and administration (e.g. updates) of the software. However, when the software requires special options to be set or modules/extensions to be enabled, it may be difficult to obtain software built to suit those requirements. In such cases, it will be required to compile the software from its source. If compiling, then it will be prudent to organize all compiled software in standard locations on the host.

Given below are the implementation steps that were used for installing PHP 5.3.3 and FreeTDS 0.91 on RHEL 6.2.

NOTE: All commands in the examples below must be executed with root privileges, unless otherwise stated.

STEP 1: Create Installation Directory Structure

  • Use the following commands to create an appropriate directory structure for compiled software:
mkdir /opt/src
  • Use a standard location (e.g. /opt) to install all software compiled from source to facilitate administration (re-compilation, removal, etc.)

STEP 2: Download and Unpack Software Source

  • Download software sources (typically *.tar.gz files) and place them in /opt/src
  • Unpack source software (*.tar.gz) as per the following examples:
tar xfz php-5.3.3.tar.gz
tar xfz freetds-0.91.tar.gz

The above commands will create directories /opt/src/php-5.3.3 and /opt/src/freetds-0.91

STEP 3: Compile and Build FreeTDS

Compile and build FreeTDS as per the example below:

cd /opt/src/freetds-0.91
./configure --prefix=/opt/freetds-0.91
make
make install

NOTE: In order to facilitate administration, you may create a soft link as follows:

cd /opt
ln -s freetds-0.91 freetds

STEP 4: Compile and Build PHP

Compile and build PHP as per the example below:

cd /opt/src/php-5.3.3
./configure --prefix=/opt/php-5.3.3 --with-config-file-path=/opt/php-5.3.3
make
make install

NOTE: In order to facilitate administration, you may create a soft link as follows:

cd /opt
ln -s php-5.3.3 php

STEP 5: Compile and Build the PHP Sybase Extension

PHP requires the sybase_ct extension to allow PHP code to interface with MSSQL. You may compile and build the sybase_ct extension as follows:

cd /opt/src/php-5.3.3/ext/sybase_ct
sh ../../scripts/phpize
./configure --prefix=/opt/php --with-php-config=/opt/php/bin/php-config --with-sybase-ct=/opt/freetds
make
make install

STEP 6: Enable the PHP Sybase Extension

Enable the sybase_ct extension by adding the following line to /opt/php/php.ini

extension=sybase_ct.so

STEP 7: Verify the PHP (with FreeTDS) Installation

If PHP and the sybase_ct extension have been successfully installed, you should be able to view the sybase_ct module when displaying the PHP configuration information as shown below:

Execute the following command (any user):

php -i | grep sybase_ct

If you see "sybase_ct" in the output, then it means that PHP and the sybase_ct extension have been successfully installed.

NOTE: Since PHP and FreeTDS have been compiled from source and installed in non-standard locations, you must add /opt/php/bin:/opt/freetds/bin to a user’s PATH environment variable.

VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)

How PAM works

Pluggable Authentication Modules (PAM) is a framework used for authentication. Typically, most Linux distros come with PAM installed by default. PAM can be powerful if used well and it’s important to understand how PAM works. PAM has its criticisms, but is quite adequate for most purposes.

Refer this LINUX FORMAT article for a good introduction to PAM.

For easy reference, I’ve stitched together an image of important PAM concepts (shown below) taken from the LINUX FORMAT article.

PAM

 

                 First published in lxf

VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Cannot connect to MySQL on a remote host

Problem:

  • Cannot connect to a MySQL database on a remote host (port 3306)
  • Firewalls aren’t blocking traffic and network connectivity is available.
  • The MySQL database is up and running on the remote host and can be accessed when connecting from to it on the remote host (as localhost)

Background:

Access to a MySQL database may be restricted and this restriction may be configured in the configuration file my.cf A directive such as bind-address=127.0.0.1 will ensure that the MySQL database can be accessed only from localhost.

Solution:

  1. Edit the configuration file my.cf and ensure that the following is set:
    bind-address=<external-ip of remote host>
  2. Restart MySQL

Root Cause:

Connectivity to the MySQL database was restricted in the my.cf configuration file with the bind-address directive.

 

NOTE:
(1) The solution above describes a successful problem-solving experience and may not be applicable to other problems with similar symptoms.
(2) Your rating of this post will be much appreciated. Also, feel free to leave comments.

 

VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

How to build AMP from source on RHEL 5.7

Typically, building a LAMP system on RHEL may be performed by yum installs. However, I wanted specific options built-in for my AMP and I wanted to locate the software in specific locations. hence, I opted to compile from source. It ain’t scary, but took me a few iterations to get stuff sorted out and this article describes what I did:

My LAMP System:

  • L – RHEL 5.7 (kernel 2.6.18-274.3.1.el5)
  • A – Apache 2.2.20
  • M – MySQL 5.5.15
  • P – PHP 5.3.8

STEP 1: Install Apache HTTP

Pre-requisites:

  • Create a user for Apache. This user will be used to launch the httpd child processes (assuming that the root user will launch the parent process to listen at port 80 (or any port < 1024). I created a user called apache as shown below (command executed as the root user):

    useradd -c "Apache HTTP" -s /bin/bash -m apache
  • Select a location to install apache and ensure that the user created in the above step has appropriate privileges. I executed the following commands as the root user:

    mkdir /opt/apache-2.2.20
    chown -R apache:apache /opt/apache-2.2.20

Installation:

As the apache user, I executed the following:

tar -xvzf httpd-2.2.20.tar.gz
cd httpd-2.2.20
./configure --prefix=/opt/apache-2.2.20 --enable-so

STEP 2: Install MySQL

Pre-requisites:

  • Create a user for MySQL. This user will be used to launch the mysqld process. I created a user called mysql as shown below (command executed as the root user):

    useradd -c "MySQL Admin" -s /bin/bash -m mysql
  • Select a location to install mysql and ensure that the user created in the above step has appropriate privileges. I executed the following commands as the root user:

    mkdir /opt/mysql-5.5.15
    chown -R mysql:mysql /opt/mysql-5.5.15
  • You may have to install some packages to build MySQL. I installed packages as per the following command (executed as the root user):

    yum install gcc gcc-c++.x86_64 cmake ncurses-devel libxml2-devel.x86_64

Installation:

As the mysql user, I executed the following:

tar -xvzf mysql-5.5.15.tar.gz
cd mysql-5.5.15
cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql-5.5.15 -DSYSCONFDIR=/opt/mysql-5.5.15
make
make install

STEP 3: Install PHP

Pre-requisites:

  • Select a location to install php and ensure that the appropriate user (web server user e.g. apache) created in the above step has appropriate privileges. I executed the following commands as the root user:

    mkdir /opt/php-5.3.8
    chown -R apache:apache /opt/php-5.3.8
  • As I needed a few packages for the phpMyAdmin application and other bespoke PHP applications, I did the following (use a combination of yum and rpm as I did not find all packages in my yum repositories):

    # As root user
    rpm -ivh libmcrypt-2.5.7-1.2.el5.rf.x86_64.rpm
    rpm -ivh libmcrypt-devel-2.5.7-1.2.el5.rf.x86_64.rpm
    rpm -ivh mhash-0.9.9-1.el5.rf.x86_64.rpm
    yum install php53-mbstring.x86_64 bzip2 bz2 libbz2 libbz2-dev autoconf
    tar -xvzf mcrypt-2.6.8.tar.gz
    cd mcrypt-2.6.8
    ./configure --disable-posix-threads --prefix=/opt/mcrypt

Installation:

As the apache user, I executed the following:

tar -xvzf php-5.3.8.tar.gz
cd php-5.3.8
./configure --prefix=/opt/php-5.3.8 --with-apxs2=/opt/apache-2.2.20/bin/apxs --with-config-file-path=/opt/php-5.3.8 --with-mysql=/opt/mysql-5.5.15 --with-bz2 --with-zlib --enable-zip --enable-mbstring --with-mcrypt
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

How to create a CSR using openssl

  • A CSR or Certificate Signing Request is an encrypted block of text that is used to request a digital certificate from a Certificate Authority (CA).
  • A CSR must be created on the server which will host the digital certificate.
  • A key pair (public/private keys) must be created before or during the creation of a CSR.
  • A CSR will contain the public key and other information provided for the certificate (Organization Name, Department Name, etc).
  • As a key pair is used in the creation of a CSR, the digital certificate provided by a CA upon receipt of your CSR must be used along with the private key used in the creation of the CSR. If the private key is lost, then the digital certificate will be useless.

Example CSR (base-64 PEM format):

-----BEGIN CERTIFICATE REQUEST-----
MIICwDCCAagCAQAwezELMAkGA1UEBhMCQ0DAYDVQQLFAVUSSZTUzEZMBcGA1
DggEPADCCAQoCggEBAPBz3Nl03nLAj766mJ1+OUjVTX9Sczeaau1s6Cdd2Wd
saddad342sdad32dBAPBz3Nl03nLAj766mJ1+OUjVTX9SczeS7u1s6CtHrmw
DggEPADCCAQoCggEBAPBz3Nl0asd21ddadsadOUjVTX9Scz4SD2d2ddadad1
DggEPADCCAQoCggEBAPBz3Nl03nLAj766mJ1+OUjVTX9Sczeau1s6CtUJ2kd
DggEPADCCAQoCggEBAPBz3Nl03nLAj766mJ1+OUjVTX9Sc527FGTDS72kkkd
-----END CERTIFICATE REQUEST-----

Given below are three methods to generate a CSR using openssl:

METHOD 1: Create a CSR and a new private key

Assuming you start from scratch, use the following command to create a CSR and a private key:

openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key

Refer the example in the screenshot below:

openssl-newcsr

METHOD 2: Create a CSR for an existing private key

If you wish to use an existing private key, use the following command to create a CSR with it:

openssl req -out CSR.csr -key privateKey.key -new

Refer the example in the screenshot below:

openssl-oldkey-newcsr

METHOD 3: Create a CSR for certificate renewal (using an existing certificate and an existing private key)

If you wish to create a CSR for certificate renewal and want to avoid re-entering certificate details, use the following command:

openssl x509 -x509toreq -in certificate.crt -out CSR.csr -signkey privateKey.key

Refer the example in the screenshot below:

openssl-oldkey-oldcert-newcsr

NOTE: The CSR file created using METHOD 3 will contain certificate and certificate request details. In this case, you must extract only the certificate request (text from and including —–BEGIN CERTIFICATE REQUEST—– to —–END CERTIFICATE REQUEST—– and submit the extract to your CA.

VN:F [1.9.22_1171]
Rating: +3 (from 3 votes)

Automate Requests for New Certificates

Recently, all Windows XP workstation users within a corporate domain were required to request and install a certificate from the Enterprise Certificate Authority (CA). Typically, the Certificate Manager Management console Snap-in Control (certmgr.msc) is used to request new certificates, as in the screenshot shown below. So, I was required to automate this process using a script that could be pushed to all the Windows XP workstations and executed.

certmgr

A tool called certreq.exe enables command-line execution of the steps performed by certmgr.msc. Hence, I developed a simple MS-DOS batch script using certreq.exe to automate the process of requesting new certificates from a CA. You may download the ZIP file below to view/use the script:

Download RequestCert.zip

Instructions to use RequestCert.zip:

(1)   Unzip RequestCert.zip using WinZip, 7-zip or your favourite decompression software. A directory called RequestCert will be created with the following files:

  • RequestCert.bat : This is the MS-DOS batch file that uses certreq.exe to automate the Certificate Request process
  • RequestCert.inf : This is the setup file containing information required by certreq.exe.
  • certreq.exe : Microsoft tool (bundled with Windows SDK) 

(2)    Edit RequestCert.bat and set the value for the variables CA_SERVER (FQDN/IP/hostname of the CA server) and CA_NAME (Name of the CA).

(3)    Edit RequestCert.inf and set the value of CertificateTemplate, if required.

(4)    Execute RequestCert.bat

 

NOTE: RequestCert.bat met my requirement which was really basic. You may amend the script and the INF file to automate Certificate Requests for other requirements.

VN:F [1.9.22_1171]
Rating: +4 (from 6 votes)

Comprehensive Perl Archive Network (CPAN) is a one-stop shop for all your Perl module requirements. While installing Foswiki, I had a requirement to install the HTML::Tree Perl module and this is the procedure which I used successfully:

STEP 1: Download the Perl module from CPAN.

I downloaded the gzipped, tarred module HTML-Tree-4.1.tar.gz from CPAN

STEP 2: Unpack the Perl module

I extracted the gzipped, tarred Perl module as follows and a directory HTML-Tree-4.1 was created :

tar xvzf HTML-Tree-4.1.tar.gz

STEP 3: Build the Perl Module

The HTML-Tree-4.1 directory (as will all Perl modules) contains a README which provided the usual installation instructions of ./Build; ./Build test and ./Build install. I did not have the Module::Build module and its dependencies and was put off by having to get all that stuff, but I had root privileges. So, I did the following as the root user, to install the HTML::Tree Perl Module:

perl Makefile.PL
make
make install
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Monitoring QTP (command-line)

Our test team uses HP QuickTest Professional (QTP) to perform data loads by importing data from an MS-Excel workbook and using a Web Form to load the data. Some data loads took a while and some were performed outside office hours. As these data loads were performed manually via the QTP GUI, QTP errors would be detected only when the Test team personnel manually check the results of the QTP run, thereby delaying further action or resolution. Given below is a solution to enable receipt of email notifications for terminating QTP errors:

STEP 1: Record and save a test using the QTP GUI

Using the QTP GUI, record the user journey for your test and save the results. Let’s assume you save the QTP test in C:\QTP\Test1

STEP 2: Customize settings using VBScript

Download the VBScript template QTPAutoRunTemplate.vbs (download zip and extract) and place it in the QTP test directory (C:\QTP\Test1). If you are familiar with the QTP Automation Object Reference model, then you may customize the test settings in this VBScript template. Note that the line qtTest.Settings.Run.OnError = "Stop" in the template. This setting was used as our requirement was to stop the QTP test upon first error. Also, this solution was built using this setting as a pre-requisite.

STEP 3: Execute QTP Test using PowerShell

Download the PowerShell Script QTPAutoRun.ps1 (download zip and extract) and do the following:

(1)    Edit the script using your favorite editor and do the following:

  • Set the $email_recipients variable on line 64 to appropriate value(s).
  • Set the $smtp_server variable on line 65 to an appropriate value.

(2)    Execute the script. This script will do the following:

  • Modify QTPAutoRunTemplate.vbs to include the path to the recorded QTP test (passed as a parameter to the script).
  • Execute QTPAutoRunTemplate.vbs and capture the results.
  • Check the results and dispatch email notifications.

NOTE: In order to execute the PowerShell Script, you must have Windows PowerShell 2.0 installed on your Windows machine. For email notification to work, you must have connectivity and authorization to use the SMTP server to relay email.

VN:F [1.9.22_1171]
Rating: +1 (from 3 votes)

Cannot connect to port 25 on a Mail server

Problem:

Cannot connect to port 25 on an MS Exchange server to use its SMTP service. A telnet test gave the following error:

telnet xx.xx.xx.xx 25
Connecting To xx.xx.xx.xx…Could not open connection to the host, on port 25: Connect failed

Background & Analysis:

One of my batch scripts used blat to send emails. However, I could not use the SMTP service on the Exchange Server. After liaising with the Exchange and Network administrators, we determined the following:

  • There was no firewall between my machine and the Exchange server and a tracert completed quickly in just 2 hops.
  • There was no firewall on the Exchange server.
  • The firewall on my machine was turned off.
  • The SMTP service was listening at port 25 on the Exchange server and was functioning properly.

Solution:

The McAfee Anti-Virus log on my machine had the following entry:

16/12/2010 12:41:02 PM Blocked by port blocking rule C:\WINDOWS\system32\telnet.exe Anti-virus Standard Protection:Prevent mass mailing worms from sending mail xx.xx.xx.xx:25

So, it was the McAfee anti-virus software that blocked outbound connections to port 25. To resolve this problem, you can add an exception to the anti-virus policy that permits your mail program (in my case, it was blat) to initiate connections to port 25 (recommended) or you may disable the anti-virus (not recommended).

Root Cause:

The Anti-virus software on the source machine had a policy enabled which prevented outbound connections to port 25.

 

NOTE:
(1) The solution above describes a successful problem-solving experience and may not be applicable to other problems with similar symptoms.
(2) Your rating of this post will be much appreciated. Also, feel free to leave comments.

 

VN:F [1.9.22_1171]
Rating: +3 (from 7 votes)

How to send emails using blat

Blat is a handy Win32 console utility that enables you to send emails via the command line, on Windows machines. This is especially useful within batch scripts.

Given below are some how-tos on basic uses of blat. Refer the blat syntax page for more options with blat. The commands below have been tested on Windows Server 2003 with blat v2.6.2, unless otherwise stated.

HOW-TO 1: Configure the SMTP Relay for blat

The blat utility can perform functions of both an MUA and an MTA. Before using blat, you may configure certain options in the Windows Registry to avoid typing them repeatedly whenever sending emails (using overrides on the command line). An example configuration is given below:

blat -installSMTP mymailer.smtp.xyz.com sender@xyz.com 5 25
#
# where:
# mymailer.smtp.xyz.com => SMTP Relay host's domain name
# sender@xyz.com => sender's email address
# 5 => Number of retries (default=1)
# 25 => SMTP Server port (default=25)
#

After executing the command in the above example, your Windows Registry should have entries for blat as shown in the image below:

Blat_RegistryInstall

HOW-TO 2: Send email with empty body

blat -s "Test mail" -i "Cybergavin Tester" -to test@abc.com -body " "
#
# where:
# -s => Subject (NOTE: If you don't provide a subject, then default subject is
#     "Contents of file: stdin.txt"
# -i => Sender's Name (NOTE: Sender's email address already configured in STEP 1)
# -to => Recipient's Email Address
# -body => blank body (blankspace within double-quotes)
#

NOTE: To send email with a body, just type the message within double-quotes in the -body option.

HOW-TO 3: Send email with body from a file

blat body.txt -s "Test mail" -i "Cybergavin Tester" -to test@abc.com
#
# where:
# -s => Subject (NOTE: If you don't provide a subject, then default subject is
#     "Contents of file: stdin.txt"
# -i => Sender's Name (NOTE: Sender's email address already configured in STEP 1)
# -to => Recipient's Email Address
# body.txt => file containing message body
#

HOW-TO 4: Send attachment(s)

blat -s "Test mail" -i "Cybergavin Tester" -to test@abc.com -body "Please see attached"
 -attach test.txt
#
# where:
# -s => Subject
# -i => Sender's Name
# -to => Recipient's Email Address
# -body => Message Body
# -attach => Binary File to be attached
#

HOW-TO 5: Send HTML email

blat body.html -s "Test mail" -i "Cybergavin Tester" -to test@abc.com -html
#
# where:
# -s => Subject (NOTE: If you don't provide a subject, then default subject is
#     "Contents of file: stdin.txt"
# -i => Sender's Name (NOTE: Sender's email address already configured in STEP 1)
# -to => Recipient's Email Address
# body.html => file containing message body in HTML format
# -html => Use HTML format (Content-Type : text/html)
#

VN:F [1.9.22_1171]
Rating: +35 (from 39 votes)

How to copy a MySQL database between servers

Copying a MySQL database from one server (MySQL server/host) to another may be done using a simple two-step process.

STEP 1: Backup the database on the source server

The mysqldump utility can be used to backup the database on the source server. An example using the root account is provided below:

mysqldump -u root --databases mytestdb > mytestdb.sql

NOTE:The "–databases" option above ensures that a "CREATE" statement for the database is written to the backup SQL, thereby enabling you to restore the database to a server where the empty database does not exist. If you do not use the "–databases" option before the database name, then the backup will still work, but in this case, you must have an empty database of the same name existing on the target server (no CREATE statement in SQL).

STEP 2: Restore the database on the target server

Restoring the database on the target server simply involves executing the "backup SQL" created on the source server.An example using the root account is provided below:

mysql --password=XXXXX < mytestdb.sql
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Using Mutt to send email

Mutt is a popular email client (MUA) which is common on Linux systems.

Given below are some how-tos on basic uses of mutt. For all UNIX utilities, the "man pages" are your best bet to learn them. I’ve just documented some popular uses of mutt. Refer the "man pages" for a more comprehensive understanding of mutt. The commands below have been tested on Red Hat Enterprise Linux 4.0 AS Update 7 with mutt v1.4.1i, unless otherwise stated.

HOW-TO 1: Send email with blank/empty body

mutt -s "Test email" testmail@abc.com < /dev/null
#
# where:
# -s => Subject
# testmail@abc.com => recipient's email address
#

HOW-TO 2: Send email with body read from a file

mutt -s "Test email" testmail@abc.com < email_body.txt
#
# where:
# -s => Subject
# testmail@abc.com => recipient's email address
# email_body.txt => file containing message body
#

HOW-TO 3: Send email with a customized sender name and email address

# The .muttrc file is Mutt's configuration file. It's default location is the $HOME directory.
# If you locate it elsewhere, specify its location with the '-F' flag.
# Add the following to the .muttrc file:
set realname="Joe Bloggs"
set from="noreply@jb.com"
set use_from=yes
#
# where:
# realname => Sender's name as it appears in the recipient's mail inbox.
# from => the "reply-to" address
# 

After configuring .muttrc, send emails as per how-tos 1 and 2.

HOW-TO 4: Send attachment(s)

mutt -s "Test email" -a file1 -a file2 testmail@abc.com < /dev/null
#
# where:
# -s => Subject
# testmail@abc.com => recipient's email address
# file1 => first attachment
# file2 => second attachment
#

HOW-TO 5: Send HTML email

I know that the technical purists out there abhor HTML emails due to potential issues with accessibility and security, but hey, there’s no denying the fact that HTML-formatted emails are far more interesting to look at than plain-text email and are better at drawing your attention to specific information (ask the marketing guys and senior executives!). HTML-formatted emails are supported by Mutt versions 1.5 and higher. Here’s how you may send an HTML-formatted email using mutt v1.5.21:

mutt -e "set content_type=text/html" -s "Test email" testmail@abc.com < welcome.html
#
# where:
# -s => Subject
# testmail@abc.com => recipient's email address
# -e => command to execute
# content_type => email body MIME type
#

The MIME type multipart/alternative ensures your emails are received properly by both plain-text and HTML clients, but it does not work well with mutt at present.

VN:F [1.9.22_1171]
Rating: +4 (from 8 votes)
 Page 1 of 3  1  2  3 »