Thursday, October 28, 2010

Sending mails from command line


Sending mails using mail:
mail (mailx is the newer version) is a fantastic program that can be used for sending email from command line or from within scripts.
The following example will send an email to admin@yeswedeal.com, with subject “Apache is down” and text “Please check Apache at host name of the server”
echo “Please check Apache at `hostname`” | mail -s “Apache is down” admin@yeswedeal.com
We can cat the contents of any text file, for example, log file and it will be sent to the recipient specified
cat “/var/log/apache2/error.log” | mail -s “Apache is down” admin@yeswedeal.com
To attach a file, other than a text one, we need to uuencode (unix to unix encode) it before sending
uuencode banner.jpg banner_out.jpg | mail webmaster@yeswedeal.com
The banner.jpg is the name of input file and banner_out.jpg is the output uuencoded file that we will be sent by mail.
To have text sent alogwith the attachment, we can cat or echo that text too
(cat /var/log/apache2/error.log;uuencode banner.jpg banner.jpg) | mail -s pic webmaster@yeswedeal.com

Sending mails from using mutt:
With mutt, its same as using mail.
echo “Please check Apache at `hostname`” | mutt -s “Apache is down” admin@yeswedeal.com
or we can cat the contents of a text file to show as body text
cat /var/log/apache2/error.log | mutt -s “Apache is down” admin@yeswedeal.com
OR
mutt -s “Apache is down” admin@yeswedeal.com
To send an empty body mail, use an empty line as the mail body:
echo | mutt -s “Software upgrades for `hostname`” admin@yeswedeal.com
To attach a binary file, its even easier with mutt, just use the -a option
echo | mutt -s “New logo for the company” -a logo.gif webmaster@yeswedeal.com

Wednesday, October 27, 2010

Linux Find FC ID WWNN of a disk/LUN


If your server is connected to more than two SANs of the same type it is really hard to find what disk is on what SAN and how it is connected to your server. You can get the Fiber Channel addresses of the HBAs by typing the following commands:
# systool -c fc_host -v
Type the following command to determine the fibre channel target WWN:
# systool -c fc_transport -v

Monday, October 25, 2010

Change location on Cent OS / RedHat /Fedora

[root@convirt kitbag]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
 1) Africa
 2) Americas
 3) Antarctica
 4) Arctic Ocean
 5) Asia
 6) Atlantic Ocean
 7) Australia
 8) Europe
 9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5
Please select a country.
 1) Afghanistan          18) Israel            35) Palestine
 2) Armenia          19) Japan            36) Philippines
 3) Azerbaijan          20) Jordan            37) Qatar
 4) Bahrain          21) Kazakhstan        38) Russia
 5) Bangladesh          22) Korea (North)        39) Saudi Arabia
 6) Bhutan          23) Korea (South)        40) Singapore
 7) Brunei          24) Kuwait            41) Sri Lanka
 8) Cambodia          25) Kyrgyzstan        42) Syria
 9) China          26) Laos            43) Taiwan
10) Cyprus          27) Lebanon            44) Tajikistan
11) East Timor          28) Macau            45) Thailand
12) Georgia          29) Malaysia            46) Turkmenistan
13) Hong Kong          30) Mongolia            47) United Arab Emirates
14) India          31) Myanmar (Burma)        48) Uzbekistan
15) Indonesia          32) Nepal            49) Vietnam
16) Iran          33) Oman            50) Yemen
17) Iraq          34) Pakistan
#? 14

The following information has been given:

    India

Therefore TZ='Asia/Kolkata' will be used.
Local time is now:    Mon Oct 25 14:52:34 IST 2010.
Universal Time is now:    Mon Oct 25 09:22:34 UTC 2010.
Is the above information OK?
1) Yes
2) No
#? 1

You can make this change permanent for yourself by appending the line
    TZ='Asia/Kolkata'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Kolkata

Installing Postfix Admin on Cent OS / RedHat / Fedora

1. Install the Postfix Admin requirements using the command below.
#yum install mysql-server php-mysql php-imap httpd postfix dovecot
 
2. Download the latest stable version of Postfix Admin in .tar.gz format. 
Assuming you got the file postfixadmin-2.3.2.tar.gz and it is located on your Desktop,
 type in the commands below to extract and to put it into its proper directory.
 
#tar xvfz postfixadmin-2.3.2.tar.gz
#mv postfixadmin-2.3.2 /usr/share/postfixadmin 
#vim /etc/httpd/conf.d/postfixadmin.conf
 
#
#  Web application to manage Postfix email server
#

Directory "/usr/share/postfixadmin"
Order Allow,Deny
Allow from all
Directory

Alias /postfixadmin /usr/share/postfixadmin
Alias /PostFixAdmin /usr/share/postfixadmin
Alias /PostfixAdmin /usr/share/postfixadmin

3. Edit the file /usr/share/postfixadmin/config.inc.php and update the following lines below.
$CONF['configured'] = true;
$CONF['postfix_admin_url'] = '/postfixadmin';
$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = 'your_password';
$CONF['database_name'] = 'postfix';
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['encrypt'] = 'cleartext';
$CONF['emailcheck_resolve_domain] = 'NO';

#service mysqld start

4.Launch the MySQL command line tool using the command below.
mysql -u root -p

The default root password of MySQL is a blank password. Next, create a 
new MySQL database for Postfix Admin using the commands below.
mysql> CREATE DATABASE postfix;
mysql> CREATE USER postfix@localhost IDENTIFIED BY 'your_password';
mysql> GRANT ALL PRIVILEGES ON postfix.* TO postfix;

#service httpd start
 
5.Go to the Postfix Admin setup page at http://localhost/postfixadmin/setup.php and fill in the setup password. Next, click the Generate password hash.
6.Get the generated setup password hash and put it into the file /usr/share/postfixadmin/config.inc.php. Next, fill in the Setup password, Admin and Password and Password (again). Finally, click Add Admin to create a new admin account.
7. Go to the Postfix Admin login page at http://localhost/postfixadmin/ and login using your newly created admin account.
 
:)