Wednesday, 20 March 2013

Shell Script Examples

1. Shell Script : Find All Zip / Rar Files Then Unzip / Unrar

Shell Script

Server1:~$ cat rar.sh

#!/bin/bash #this line must be in every bash script, just ensure that you use correct path

list=`find /home/yevhen/ -type f -name “*.rar”` # get list of file and write this list to variable with name list, find command used to find all files (-type f) where name match *.rar (-name key)

for line in $list; do # this line take every line from list to line variable

DEST=${line%/*} # remove from line filename, so just destination will be in DEST variable.

unrar x $line $DEST # unrar file from line variable to DEST dir

done # finish of for loop.

Output

    Server1:~$ ./rar.sh

    UNRAR 3.93 freeware Copyright (c) 1993-2010 Alexander Roshal

    Extracting from /home/yevhen/Dropbox/Yevhen/test.rar

    Extracting /home/yevhen/Dropbox/Yevhen/wget.sh OK
    All OK

    UNRAR 3.93 freeware Copyright (c) 1993-2010 Alexander Roshal

    Extracting from /home/yevhen/Pictures/test.rar

    Extracting /home/yevhen/Pictures/wget.sh OK
    All OK


===============================================30000
2. Shell Script To Check Disk Usage Is Out Of Space

Shell Script

    #!/bin/bash

    threshold=”20″ # This set threshold value

    i=2 #Counter, will be used later, set to 2, since first line in df output is description.

    result=`df -kh |grep -v “Filesystem” | awk ‘{ print $5 }’ | sed ‘s/%//g’` # Getting list of percentage of all disks, df -kh show all disk usage, grep -v – without description line, awk ‘{ print $5 }’ – we need only 5th value from line and sed ‘s/%//g’ – to remove % from result.

    for percent in $result; do # for every value in result we start loop.

    if ((percent > threshold)) # compare, if current value bigger than threshold, if yes next lines.
    then

    partition=`df -kh | head -$i | tail -1| awk ‘{print $1}’` # taking name of partition, here we use counter. Df list of all partitions, head – take only $i lines from top, tail -1 take only last line, awk ‘{print $1}’ – take only first value in line.

    echo “$partition at $(hostname -f) is ${percent}% full” #print to console – what partition and how much used in %.

    fi # end of if loop

    let i=$i+1 # counter increased by 1.

    done # end of for loop.

Shell Script Result


    Server:~/$ df -kh
    Filesystem Size Used Avail Use% Mounted on
    /dev/sda1 52G 4.7G 45G 10% /
    tmpfs 1.9G 0 1.9G 0% /lib/init/rw
    udev 1.9G 192K 1.9G 1% /dev
    tmpfs 1.9G 2.6M 1.9G 1% /dev/shm
    /dev/sda6 92G 22G 66G 25% /home

    Server:~/$ ./df_script.sh
    /dev/sda6 at yevhen.lviv.example.com is 25% full

==========================================
3. Shell Script : Check Ping To Remote Host And Port Opened

Shell Script

Test Ping And Open Port

    #!/bin/bash

    # check if service name passed to script as argument, if there no arguments (0) do next

    if [ "$#" = "0" ];

    then

    #write to terminal usage

    echo “Usage: $0 ”

    #since no arguments – we need to exit script and user re-run

    exit 1
    fi

    #writing parameters to variables

    host=$1
    port=$2
    email=”test@expertslogin.com”
    subject=”Script result”

    #Check if ping ok -q to quite mod, -c 4 for 4 checks

    if ping -q -c 4 $host >/dev/null
    then
    # next lines writes result variable

    ping_result=”OK”
    else
    ping_result=”NOT OK”

    fi #end of fi loop

    #next command check if port opened via nc command, and getting exit status of nc command

    nc_result=`nc -z $host $port; echo $?`

    #check of exit status of nc command, and write results to variables

    if [ $nc_result != 0 ];
    then
    port_result=”not opened”
    else
    port_result=”opened”
    fi #exit of fi loop

    #writing message that script will email and write to output

    message=”Ping to host – ${ping_result}, port $port ${port_result}.”

    #next check if ping or port check is failed (ping if not OK and exit status of nc if not 0)

    if [ "$ping_result" != "OK" -o "$nc_result" != "0" ];
    then
    echo “$message” #this line write warning message to terminal

    echo “$message” | mail -s “$subject” $email #this line send email

    fi

< h3="">

Ping to localhost and check is 22 port opened (ssh server)

    desktop:~/$ ./script 127.0.0.1 22
    Ping to host – OK, port 22 not opened.
    desktop:~/$

<>


===================================================

4. Shell Script : Service Status Check And start If It’s Not Running

Shell Script

    #!/bin/bash

    if [ "$#" = 0 ] # check if service name passed to script as argument, if there no arguments (0) do next

    then
    echo “Usage $0 ” #write to terminal usage

    exit 1 #since no arguments – we need to exit script and user re-run it

    fi

    service=$1 #get service name from first argument

    is_running=`ps aux | grep -v grep| grep -v “$0″ | grep $service| wc -l | awk ‘{print $1}’` #this check
    #if service running using ps command, after we remove our process from output, since script will also
    # match, with wc we count number of matching lines .

    if [ $is_running != "0" ] ; # is number of lines are not 0 do next

    then

    echo “Service $service is running” #just put this line to terminal

    else #if number of precesses is 0

    echo “Service $service is not running” #just put this string to terminal

    initd=`ls /etc/init.d/ | grep $service | wc -l | awk ‘{ print $1 }’` #checking for files in /etc/init.d
    #(directory with start-up scripts) with name similar to service

    if [ $initd = "1" ]; #if there is script with similar name

    then
    startup=`ls /etc/init.d/ | grep $service` # this line get name of startup script (ls –
    # lists files in directory

    echo -n “Found startap script /etc/init.d/${startup}. Start it? Y/n ? ” #just put to
    #terminal this line

    read answer #waiting for user answer

    if [ $answer = "y" -o $answer = "Y" ]; #if answer Y or y

    then
    echo “Starting service…”

    /etc/init.d/${startup} start # running startup script

    fi #exit of if loop

    fi #exit of if loop

    fi#exit of if loop

Results

    server:~/$ ./service.sh apparmor
    Service apparmor is not running
    Found startap script /etc/init.d/apparmor. Start it? Y/n ? Y
    Starting service…
    * Starting AppArmor profiles [OK]

How To Configure Iscsi Storage On Redhat Linux

Show current installed redhat version and update

[root@CSSW2013NOC3 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.7 (Tikanga)

Display Architecture

[root@CSSW2013NOC3 ~]# getconf LONG_BIT
64

Check isci initiator installed or not (You need iscsi-initiator-utils-6.2.0.742-0.6.el5 or greater)

[root@CSSW2013NOC3 ~]# rpm -qa | grep -i iscsi
iscsi-initiator-utils-6.2.0.872-10.el5

Display interfaces and IP address details

[root@CSSW2013NOC3 ~]# ifconfig -a | more

eth0 Link encap:Ethernet HWaddr 00:50:56:AB:00:E7
inet addr:172.28.*.* Bcast:172.28.12.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2503 errors:0 dropped:0 overruns:0 frame:0
TX packets:838 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:196784 (192.1 KiB) TX bytes:98212 (95.9 KiB)
eth1 Link encap:Ethernet HWaddr 00:50:56:AB:00:E8
inet addr:172.28.*.* Bcast:172.28.40.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4237 errors:0 dropped:0 overruns:0 frame:0
TX packets:3807 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:966177 (943.5 KiB) TX bytes:359247 (350.8 KiB)
eth2 Link encap:Ethernet HWaddr 00:50:56:AB:01:00
inet addr:172.28.*.* Bcast:172.28.40.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4387 errors:0 dropped:0 overruns:0 frame:0
TX packets:3960 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:894415 (873.4 KiB) TX bytes:384013 (375.0 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:660 (660.0 b) TX bytes:660 (660.0 b)

Creating the interface files for MPIO

[root@CSSW2013NOC3 ~]# iscsiadm -m iface -I eth1 -o new
New interface eth1 added
[root@CSSW2013NOC3 ~]# iscsiadm -m iface -I eth2 -o new
New interface eth2 added

Updating the interface name for each port

[root@CSSW2013NOC3 x ~]# iscsiadm -m iface -I eth1 -o update -n iface.net_ifacename -v eth1
eth1 updated.
[root@CSSW2013NOC3 ~]# iscsiadm -m iface -I eth2 -o update -n iface.net_ifacename -v eth2
eth2 updated.
[root@CSSW2013NOC3 ~]# cat /var/lib/iscsi/ifaces/eth1
# BEGIN RECORD 2.0-872
iface.iscsi_ifacename = eth1
iface.net_ifacename = eth1
iface.transport_name = tcp
# END RECORD
[root@CSSW2013NOC3 ~]# cat /var/lib/iscsi/ifaces/eth2
# BEGIN RECORD 2.0-872
iface.iscsi_ifacename = eth2
iface.net_ifacename = eth2
iface.transport_name = tcp
# END RECORD

Iscsi target Discovering using iscsiadm command

[root@CSSW2013NOC3 ~]# iscsiadm -m discovery -t st -p 172.28.*.*:3260
172.28.*.*:3260,1 iqn.2001-05.com.equallogic:0-8a0906-a146b2a07-57858e634784f7b0-bobrhel
172.28.*.*:3260,1 iqn.2001-05.com.equallogic:0-8a0906-a146b2a07-57858e634784f7b0-bobrhel

Logging into target ( You have option to login individually also)

[root@CSSW2013NOC3 ~]# iscsiadm -m node -l
Logging in to [iface: eth2, target: iqn.2001-05.com.equallogic:0-8a0906-a146b2a07-57858e634784f7b0-bobrhel, portal: 172.28.*.*,3260]
Logging in to [iface: default, target: iqn.2001-05.com.equallogic:0-8a0906-a146b2a07-57858e634784f7b0-bobrhel, portal: 172.28.*.*,3260]
Logging in to [iface: eth1, target: iqn.2001-05.com.equallogic:0-8a0906-a146b2a07-57858e634784f7b0-bobrhel, portal: 172.28.*.*,3260]
Login to [iface: eth2, target: iqn.2001-05.com.equallogic:0-8a0906-a146b2a07-57858e634784f7b0-bobrhel, portal: 172.28.*.*,3260] successful.
Login to [iface: default, target: iqn.2001-05.com.equallogic:0-8a0906-a146b2a07-57858e634784f7b0-bobrhel, portal: 172.28.*.*,3260] successful.
Login to [iface: eth1, target: iqn.2001-05.com.equallogic:0-8a0906-a146b2a07-57858e634784f7b0-bobrhel, portal: 172.28.*.*,3260] successful.

Display scsi attached device

[root@CSSW2013NOC3 ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: VMware Model: Virtual disk Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi7 Channel: 00 Id: 00 Lun: 00
Vendor: EQLOGIC Model: 100E-00 Rev: 5.2
Type: Direct-Access ANSI SCSI revision: 05
Host: scsi6 Channel: 00 Id: 00 Lun: 00
Vendor: EQLOGIC Model: 100E-00 Rev: 5.2
Type: Direct-Access ANSI SCSI revision: 05

Below command will display Iscsi session details

[root@CSSW2013NOC3 ~]# iscsiadm -m session
tcp: [6] 172.28.*.*:3260,1 iqn.2001-05.com.equallogic:0-8a0906-a146b2a07-57858e634784f7b0-bobrhel
tcp: [7] 172.28.*.*:3260,1 iqn.2001-05.com.equallogic:0-8a0906-a146b2a07-57858e634784f7b0-bobrhel

Friday, 8 March 2013

How to clear Qmail mail queue?


How to clear Qmail mail queue?
---------------------------------------
NAME
     qmail-clean - clean up the queue directory

SYNOPSIS
     qmail-clean

DESCRIPTION
     qmail-clean reads a cleanup command from descriptor 0,  per-
     forms  the  cleanup, prints the results to descriptor 1, and
     repeats.
----------------------------------------
1. First of all check the number of messages from the queue using the qmail-qstat tool:
[root@CSSW2013NOC3 ~]# /var/qmail/bin/qmail-qstat
messages in queue: 22463
messages in queue but not yet preprocessed: 22
2. To remove the messages from the queue ALWAYS stop the qmail service first, to avoid having to reconfigure it again:
[root@CSSW2013NOC3 ~]#service qmail stop
3. Once the service is stopped execute the following commands one by one (based on the number of files stuck in the queue, this may take a while):
#find /var/qmail/queue/mess -type f -exec rm {} \;#find /var/qmail/queue/info -type f -exec rm {} \;#find /var/qmail/queue/local -type f -exec rm {} \;#find /var/qmail/queue/intd -type f -exec rm {} \;#find /var/qmail/queue/todo -type f -exec rm {} \;#find /var/qmail/queue/remote -type f -exec rm {} \;
4. Finally start the mail service and recheck the queue to ensure that all the messages have been removed:
[root@CSSW2013NOC3 ~]#service qmail start
To automate this process:: I have two scripts available (basically are performing the same operations as above). For those that receive oversized file truncating errors please use the 2nd script – it takes a little longer but gets the job done.
wget http://dragos.fedorovici.com/qmailclear.sh
wget http://dragos.fedorovici.com/qmailclean.sh

[root@CSSW2013NOC3 ~]$sh qmailclean.sh
[root@CSSW2013NOC3 ~]#sh qmailclear.sh

qmail Installation Steps on Linux


**************************qmail Installation *************************

1. Download the source


2. System requirements

[sankar@CSSW2013NOC3 ~]$ rpm -qa | grep gcc
gcc-4.4.6-4.el6.i686
libgcc-4.4.6-4.el6.i686

3. Unpack the distribution
Copy or move the tarballs to the directory you want to do the work in. /usr/local/src is a good choice for qmail and ucspi-tcp. daemontools should be built under /package.

[sankar@CSSW2013NOC3 ~]$ su -
Password:

[root@CSSW2013NOC3 ~]# mkdir -p /usr/local/src

[root@CSSW2013NOC3 ~]#mkdir -p /package

[root@CSSW2013NOC3 ~]#mv netqmail-1.06.tar.gz ucspi-tcp-0.88.tar.gz /usr/local/src

[root@CSSW2013NOC3 ~]#mv daemontools-0.76.tar.gz /package

[root@CSSW2013NOC3 ~]#chmod 1755 /package

Now you can unpack the packages:

[root@CSSW2013NOC3 ~]#cd /usr/local/src

[root@CSSW2013NOC3 src]#tar -xvzf netqmail-1.06.tar.gz

[root@CSSW2013NOC3 src]#tar -xvzf ucspi-tcp-0.88.tar.gz

[root@CSSW2013NOC3 ~]#cd /package

[root@CSSW2013NOC3 ~]#tar -xvzf daemontools-0.76.tar.gz

There should now be directories called

/usr/local/src/netqmail-1.06,
/usr/local/src/ucspi-tcp-0.88, and
/package/admin/daemontools-0.76.
4. Create directories :

To create the qmail "home" directory:

[root@CSSW2013NOC3 ~]#mkdir /var/qmail

The qmail configuration files can be stored in /etc/qmail by doing:

[root@CSSW2013NOC3 ~]#mkdir /etc/qmail
[root@CSSW2013NOC3 ~]#ln -s /etc/qmail /var/qmail/control

5. Create users and groups :

[root@CSSW2013NOC3 ~]#cd /usr/local/src/netqmail-1.06

[root@CSSW2013NOC3 ~]#cp INSTALL.ids IDS

[root@CSSW2013NOC3 netqmail-1.06]# cat IDS
groupadd nofiles
useradd -g nofiles -d /var/qmail/alias alias
useradd -g nofiles -d /var/qmail qmaild
useradd -g nofiles -d /var/qmail qmaill
useradd -g nofiles -d /var/qmail qmailp
groupadd qmail
useradd -g qmail -d /var/qmail qmailq
useradd -g qmail -d /var/qmail qmailr
useradd -g qmail -d /var/qmail qmails

:wq

[root@CSSW2013NOC3 ~]#chmod 700 IDS

[root@CSSW2013NOC3 ~]#/bin/sh IDS (or) ./IDS

Start by using your favorite editor and editing /etc/group. You need to add the
following two lines to the end of the file:

#nano /etc/group

qmail:*:2107:
nofiles:*:2108:

Note: vipw equal to vi /etc/passwd

[root@CSSW2013NOC3 ~]#vipw

add these lines to the end of the file(/etc/passed):


alias:*:7790:2108::/var/qmail/alias:/bin/true
qmaild:*:7791:2108::/var/qmail:/bin/true
qmaill:*:7792:2108::/var/qmail:/bin/true
qmailp:*:7793:2108::/var/qmail:/bin/true
qmailq:*:7794:2107::/var/qmail:/bin/true
qmailr:*:7795:2107::/var/qmail:/bin/true
qmails:*:7796:2107::/var/qmail:/bin/true

6. Do the build :

Now you can start building qmail.

[root@CSSW2013NOC3 ~]#cd /usr/local/src/netqmail-1.06

[root@CSSW2013NOC3 netqmail-1.06]# make setup check

If your DNS is configured properly, this script should be all you need at this point:

[root@CSSW2013NOC3 netqmail-1.06]# ./config

[root@CSSW2013NOC3 netqmail-1.06]# ./config-fast the.full.hostname

7. Install ucspi-tcp :

[root@CSSW2013NOC3 ~]#cd /usr/local/src/ucspi-tcp-0.88

[root@CSSW2013NOC3 ucspi-tcp-0.88]#patch < /usr/local/src/netqmail-1.06/other-patches/ucspi-tcp-0.88.errno.pat

[root@CSSW2013NOC3 ucspi-tcp-0.88]#make

[root@CSSW2013NOC3 ucspi-tcp-0.88]#make setup check

8.Install daemontools

[root@CSSW2013NOC3 ~]#cd /package/admin/daemontools-0.76

[root@CSSW2013NOC3 daemontools-0.76 ]#cd src

[root@CSSW2013NOC3 src]#patch < /usr/local/src/netqmail-1.06/other-patches/daemontools-0.76.errno.patch

[root@CSSW2013NOC3 ~]#./package/install

[root@CSSW2013NOC3 package]# ps -ef | grep svscan
root 7978 5121 0 16:34 pts/2 00:00:00 grep svscan
9.Start qmail :

copy this script into /var/qmail/rc

[root@CSSW2013NOC3 ~]#nano /var/qmail/rc

#!/bin/sh
# Using stdout for logging
# Using control/defaultdelivery from qmail-local to deliver messages by default

exec env - PATH="/var/qmail/bin:$PATH" \
qmail-start "`cat /var/qmail/control/defaultdelivery`"


[root@CSSW2013NOC3 ~]#chmod 755 /var/qmail/rc

[root@CSSW2013NOC3 ~]#mkdir /var/log/qmail

At this point you need to decide the default delivery mode for messages that aren't delivered by a
.qmail file.


10. System start-up files :

This is accomplished by creating a startup/shutdown script like the following in
/var/qmail/bin/qmailctl:

Note:This script is available via http://lifewithqmail.org/qmailctl-script-dt70.

Copy this script into /var/qmail/bin/qmailctl.
Make the qmailctl script executable and link it to a directory in your path:

[root@CSSW2013NOC3 ~]#chmod 755 /var/qmail/bin/qmailctl

[root@CSSW2013NOC3 ~]#ln -s /var/qmail/bin/qmailctl /usr/bin


11. The supervise scripts :

Now create the supervise directories for the qmail services:

[root@CSSW2013NOC3 ~]#mkdir -p /var/qmail/supervise/qmail-send/log

[root@CSSW2013NOC3 ~]#mkdir -p /var/qmail/supervise/qmail-smtpd/log

Create the /var/qmail/supervise/qmail-send/run file:

Copy this script into /var/qmail/supervise/qmail-send/run

[root@CSSW2013NOC3 ~]#nano /var/qmail/supervise/qmail-send/run
#!/bin/sh
exec /var/qmail/rc
Create the /var/qmail/supervise/qmail-send/log/run file:
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail
Create the /var/qmail/supervise/qmail-smtpd/run file:
#!/bin/sh
QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`
LOCAL=`head -1 /var/qmail/control/me`
if [ -z "$QMAILDUID" -o -z "$NOFILESGID" -o -z "$MAXSMTPD" -o -z "$LOCAL" ]; th
echo QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in
echo /var/qmail/supervise/qmail-smtpd/run
exit 1
fi
if [ ! -f /var/qmail/control/rcpthosts ]; then
echo "No /var/qmail/control/rcpthosts!"
echo "Refusing to start SMTP listener because it'll create an open relay"
exit 1
fi
exec /usr/local/bin/softlimit -m 2000000 \
/usr/local/bin/tcpserver -v -R -l "$LOCAL" -x /etc/tcp.smtp.cdb -c "$MAXSMT
-u "$QMAILDUID" -g "$NOFILESGID" 0 smtp /var/qmail/bin/qmail-smtpd 2>&1

Create the concurrencyincoming control file:

[root@CSSW2013NOC3 ~]#echo 20 > /var/qmail/control/concurrencyincoming
[root@CSSW2013NOC3 ~]#chmod 644 /var/qmail/control/concurrencyincoming

Create the /var/qmail/supervise/qmail-smtpd/log/run file:

[sankar@CSSW2013NOC3 ~]$ nano /var/qmail/supervise/qmail-smtpd/run
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/smtpd


[root@CSSW2013NOC3 ~]#chmod 755 /var/qmail/supervise/qmail-send/run

[root@CSSW2013NOC3 ~]#chmod 755 /var/qmail/supervise/qmail-send/log/run

[root@CSSW2013NOC3 ~]#chmod 755 /var/qmail/supervise/qmail-smtpd/run

[root@CSSW2013NOC3 ~]#chmod 755 /var/qmail/supervise/qmail-smtpd/log/run

12. Then set up the log directories:

[root@CSSW2013NOC3 ~]#mkdir -p /var/log/qmail/smtpd

[root@CSSW2013NOC3 ~]#chown qmaill /var/log/qmail /var/log/qmail/smtpd

Finally, link the supervise directories into /service:
[root@CSSW2013NOC3 ~]#ln -s /var/qmail/supervise/qmail-send /var/qmail/supervise/qmail-smtpd /ser vice

The /service directory is created when daemontools is installed.

[root@CSSW2013NOC3 ~]#qmailctl stop

13. SMTP Access Control :

Allow the local host to inject mail via SMTP:

[root@CSSW2013NOC3 ~]#echo '127.:allow,RELAYCLIENT=""' >>/etc/tcp.smtp

[root@CSSW2013NOC3 ~]#qmailctl cdb

14.Stop and disable the installed MTA

If your existing MTA is Sendmail, you should be able to stop it by running the init.d script with
the "stop" argument. E.g., one of these should work:

/etc/init.d/sendmail stop
/sbin/init.d/sendmail stop
/etc/rc.d/init.d/sendmail stop

[root@CSSW2013NOC3 ~]#ps -ef|grep sendmail

[root@CSSW2013NOC3 ~]#kill PID-of-sendmail

[root@CSSW2013NOC3 sankar]# netstat -a | grep smtp
tcp 0 0 localhost:smtp *:* LISTEN
unix 2 [ ACC ] STREAM LISTENING 12541 private/smtp
If something is running, make sure it's not qmail by doing:

[root@CSSW2013NOC3 sankar]#qmailctl stop

The repeat the netstat check:

[root@CSSW2013NOC3 sankar]#netstat -a | grep smtp

The last step is to create a couple of system aliases.

15. Create System Aliases

There are three system aliases that should be created on all qmail installations:

To create these aliases, decide where you want each of them to go (a local user or a remote address)
and create and populate the appropriate .qmail files.

For example, say local user Sankar is both the system and mail administrator:

echo sankar > /var/qmail/alias/.qmail-root
echo sankar > /var/qmail/alias/.qmail-postmaster
ln -s .qmail-postmaster /var/qmail/alias/.qmail-mailer-daemon
ln -s .qmail-postmaster /var/qmail/alias/.qmail-abuse
chmod 644 /var/qmail/alias/.qmail-root /var/qmail/alias/.qmail-postmaster


16.Start qmail
If you stopped qmail above after creating the links in /service, you should restart it now:

[root@CSSW2013NOC3 ~]#qmailctl start

17.Test the Installation
[root@CSSW2013NOC3 ~]#qmailctl stat

/service/qmail-send: up (pid 30303) 187 seconds
/service/qmail-send/log: up (pid 30304) 187 seconds
/service/qmail-smtpd: up (pid 30305) 187 seconds
/service/qmail-smtpd/log: up (pid 30308) 187 seconds
messages in queue: 0
messages in queue but not yet preprocessed: 0

Note:All four services should be "up" for more than a second . If they're not, the installation step-by-step and double check your work. You can also download and run the inst_check script, available from http://lifewithqmail.org/inst_check. For
example:
# sh inst_check
! /var/log/qmail has wrong owner, should be qmaill
...try: chown qmaill /var/log/qmail


If inst_check finds problems, fix them and re-run it. When everything looks right, inst_check
will report:
Congratulations, your LWQ installation looks good!

Troubleshooting:

# ps -efl | grep "service errors" | grep -v grep
000 S root 1006 1001 0 76 0 - 334 pipe_w Mar31 ? 00:0
readproctitle service errors: ...unable to start qmail-smtpd/run: exec form
#

In this case, the problem is that there is an error in the first line of the
/service/qmail-smtpd/run script--most likely caused ,

It sometimes helps to run a service manually in order to find configuration problems. For example, if
your qmail-smtpd/log service isn't running, do:


[root@CSSW2013NOC3 ~]#cd /service/qmail-smtpd/log

[root@CSSW2013NOC3 ~]#svc -d .

[root@CSSW2013NOC3 ~]#./run

if no errors, enter a line of text and press ENTER
if still no errors, enter CTRL-D (end of file)

At this point, you should be able to identify the problem and fix it. Once that's done, return to the
service's directory, if necessary, and do:

[root@CSSW2013NOC3 ~]#svc -u .