Wednesday, June 5, 2013

Shell script to find the disk details of Remote server in Linux


Sample shell script to find the disk details of remote server in linux. Here i denotes the server from 1 to 13 and shark1 is the file where the output are stored.

In Shell script you may need to disable host key checking using StrictHostKeyChecking

For more details on sshpass Click here

for i in `seq 1 1 13`; do sshpass -ftest.txt  ssh -o  StrictHostKeyChecking=no  tester@xxx$i.example.com "hostname && df -Th " >> shark1; done

[root@test ~]# cat shark1
xxx1.
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda3     ext3     39G   18G   20G  47% /
/dev/sda5     ext3    2.0G   74M  1.8G   4% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G   88G  117G  43% /data
/dev/sda1     ext3    190M   18M  163M  10% /boot
tmpfs        tmpfs     16G     0   16G   0% /dev/shm

xxx2

Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda3     ext3     39G   22G   16G  58% /
/dev/sda5     ext3    2.0G  446M  1.5G  24% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G  184G   21G  90% /data
/dev/sda1     ext3    190M   18M  163M  10% /boot
tmpfs        tmpfs     16G     0   16G   0% /dev/shm

xxx3

Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda3     ext3     39G   22G   15G  60% /
/dev/sda5     ext3    2.0G   47M  1.8G   3% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G  143G   62G  70% /data
/dev/sda1     ext3    190M   18M  163M  10% /boot
tmpfs        tmpfs     16G     0   16G   0% /dev/shm

xxx4

Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda3     ext3     39G   16G   21G  44% /
/dev/sda5     ext3    2.0G   36M  1.9G   2% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G  136G   69G  67% /data
/dev/sda1     ext3    190M   18M  163M  10% /boot
tmpfs        tmpfs     16G     0   16G   0% /dev/shm

xxx5

Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda3     ext3     39G   28G  9.0G  76% /
/dev/sda5     ext3    2.0G  1.5G  399M  79% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G  186G   19G  91% /data
/dev/sda1     ext3    190M   18M  163M  10% /boot
tmpfs        tmpfs     16G     0   16G   0% /dev/shm

xxx6
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda3     ext3     39G   25G   13G  67% /
/dev/sda5     ext3    2.0G   44M  1.8G   3% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G   75G  130G  37% /data
/dev/sda1     ext3    190M   18M  163M  10% /boot
tmpfs        tmpfs     16G     0   16G   0% /dev/shm

xxx7
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda3     ext3     39G   22G   16G  58% /
/dev/sda5     ext3    2.0G   36M  1.9G   2% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G  3.7G  201G   2% /data
/dev/sda1     ext3    190M   18M  163M  10% /boot
tmpfs        tmpfs     16G     0   16G   0% /dev/shm

xxx8
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda3     ext3     39G   23G   15G  61% /
/dev/sda5     ext3    2.0G   44M  1.8G   3% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G  167G   38G  82% /data
/dev/sda1     ext3    190M   18M  163M  10% /boot
tmpfs        tmpfs     16G     0   16G   0% /dev/shm

xxx9
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda5     ext3     39G  5.0G   32G  14% /
/dev/sda3     ext3    2.0G   36M  1.9G   2% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G  2.1G  202G   2% /data
/dev/sda1     ext3    190M   18M  163M  10% /boot
tmpfs        tmpfs     16G     0   16G   0% /dev/shm

xxx10
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda5     ext3     39G   15G   22G  41% /
/dev/sda3     ext3    2.0G   68M  1.8G   4% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G   97G  107G  48% /data
/dev/sda1     ext3    190M   12M  169M   7% /boot
tmpfs        tmpfs    7.9G     0  7.9G   0% /dev/shm

xxx11
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda2     ext3     39G   28G  9.7G  74% /
/dev/sda5     ext3    2.0G  913M  969M  49% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G   91G  114G  45% /data
/dev/sda1     ext3    190M   12M  169M   7% /boot
tmpfs        tmpfs     32G     0   32G   0% /dev/shm

xxx12
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda2     ext3     39G   21G   17G  55% /
/dev/sda5     ext3    2.0G  1.2G  679M  64% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G  163G   42G  80% /data
/dev/sda1     ext3    190M   12M  169M   7% /boot
tmpfs        tmpfs     32G     0   32G   0% /dev/shm

xxx13
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda2     ext3     39G   32G  5.7G  85% /
/dev/sda5     ext3    2.0G  956M  925M  51% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G  163G   42G  80% /data
/dev/sda1     ext3    190M   12M  169M   7% /boot
tmpfs        tmpfs     32G     0   32G   0% /dev/shm

Steps to Uninstall Zimbra in Linux

uninstall

[root@test zcs-7.2.3_GA_2872.RHEL5.20130304144834]# su - zimbra
[zimbra@test ~]$ zmcontrol stop
Host localhost
        Stopping zmconfigd...Done.
        Stopping stats...Done.
        Stopping spell...Done.
        Stopping snmp...Done.
        Stopping cbpolicyd...Done.
        Stopping archiving...Done.
        Stopping antivirus...Done.
        Stopping antispam...Done.
        Stopping imapproxy...Done.
        Stopping memcached...Done.
        Stopping mailbox...Done.
        Stopping logger...Done.
[zimbra@test ~]
[zimbra@test ~]$ exit
logout

[root@test zcs-7.2.3_GA_2872.RHEL5.20130304144834]# ./install.sh -u

Operations logged to /tmp/install.log.12665
Checking for existing installation...      
    zimbra-ldap...NOT FOUND                
    zimbra-logger...NOT FOUND              
    zimbra-mta...NOT FOUND                 
    zimbra-snmp...NOT FOUND                
    zimbra-store...NOT FOUND               
    zimbra-apache...NOT FOUND              
    zimbra-spell...NOT FOUND               
    zimbra-convertd...NOT FOUND            
    zimbra-memcached...NOT FOUND           
    zimbra-proxy...NOT FOUND               
    zimbra-archiving...NOT FOUND           
    zimbra-cluster...NOT FOUND             
    zimbra-core...FOUND zimbra-core-7.2.3_GA_2872

Saving existing configuration file to /opt/zimbra/.saveconfig

Completely remove existing installation? [N] yes

Shutting down zimbra mail

Removing existing packages

   zimbra-core...done

Removing deployed webapp directories

Removing /opt/zimbra
Removing zimbra crontab entry...done.
done.
Cleaning up zimbra init scripts...done.
Cleaning up /etc/ld.so.conf...done.
Cleaning up /etc/prelink.conf...done.
Cleaning up /etc/logrotate.d/zimbra...done.
Cleaning up /etc/security/limits.conf...done.

Finished removing Zimbra Collaboration Suite.

SSHPASS command to find the details of Remote Server in linux

How to use ssh in SHELL SCRIPT. You can use sshpass command to use ssh in shell script. Below is the syntax to find the mounted partition details of the remote server from local machine.

sshpass -p 'Mute4@sec' ssh saikrishna.b@xxserver.com df

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda3             40631988  22265072  16269632  58% /
/dev/sda5              2030736    456452   1469464  24% /tmp
/dev/mapper/VolGroup00-data
                     225522932 191902676  21979424  90% /data
/dev/sda1               194442     17793    166610  10% /boot
tmpfs                 16470432         0  16470432   0% /dev/shm

[root@test ~]# cat test.txt

Mute4@sec

With out showing the password you can store the password in a file and call them . Here -f denotes file and test.txt is the file where the password has been stored.

[root@test1 ~]# sshpass -ftest.txt ssh saikrishna.b@xxxserver.com df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda3             40631988  22265120  16269584  58% /
/dev/sda5              2030736    456452   1469464  24% /tmp
/dev/mapper/VolGroup00-data
                     225522932 191905108  21976992  90% /data
/dev/sda1               194442     17793    166610  10% /boot
tmpfs                 16470432         0  16470432   0% /dev/shm

[root@test1 ~]# sshpass -ftest.txt ssh saikrishna.b@xxxx.com "df -Th"
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda3     ext3     39G   22G   16G  58% /
/dev/sda5     ext3    2.0G  446M  1.5G  24% /tmp
/dev/mapper/VolGroup00-data
              ext3    216G  184G   21G  90% /data
/dev/sda1     ext3    190M   18M  163M  10% /boot
tmpfs        tmpfs     16G     0   16G   0% /dev/shm

Rebuild rpm database

Rebuilding corrupted RPM database

Method # 1

Remove /var/lib/rpm/__db* files to avoid stale locks:
# cd /var/lib
# rm __db*

Rebuild RPM database:
# rpm --rebuilddb
# rpmdb_verify Packages

Method # 2

If you are facing the issue still, try with the below commands

cd /var/lib/rpm
# mv Packages Packages_backup2013
# db_dump Packages_backup2013 | db_load Packages
# rpm -qa
# rpm --rebuilddb

Install and Configure NFS server

                                                                 
Three rpm are required to configure nfs server. nfs, portmap, xinetd check them if not found then install

[root@test ~]# rpm -qa nfs*
nfs-utils-lib-1.1.5-4.el6.x86_64
nfs-utils-1.2.3-26.el6.x86_64
nfs4-acl-tools-0.3.3-6.el6.x86_64
[root@test ~]# rpm -qa xinetd*
[root@test ~]# rpm -qa xinetd
[root@test ~]# rpm -qa portmap
[root@test ~]# yum install portmap
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: centos.aol.in                    
 * extras: centos.aol.in                  
 * updates: centos.aol.in                 
Setting up Install Process                
Resolving Dependencies                    
--> Running transaction check             
---> Package rpcbind.x86_64 0:0.2.0-9.el6 will be updated
---> Package rpcbind.x86_64 0:0.2.0-11.el6 will be an update
--> Finished Dependency Resolution                          

Dependencies Resolved

==============================================================================================================
 Package                  Arch                    Version                         Repository             Size 
==============================================================================================================
Updating:                                                                                                     
 rpcbind                  x86_64                  0.2.0-11.el6                    base                   51 k 

Transaction Summary
==============================================================================================================
Upgrade       1 Package(s)

Total download size: 51 k
Is this ok [y/N]: y
Downloading Packages:
http://centos.aol.in/6.4/os/x86_64/Packages/rpcbind-0.2.0-11.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 403"
Trying other mirror.
rpcbind-0.2.0-11.el6.x86_64.rpm                                                        |  51 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : rpcbind-0.2.0-11.el6.x86_64                                                                1/2
  Cleanup    : rpcbind-0.2.0-9.el6.x86_64                                                                 2/2
  Verifying  : rpcbind-0.2.0-11.el6.x86_64                                                                1/2
  Verifying  : rpcbind-0.2.0-9.el6.x86_64                                                                 2/2

Updated:
  rpcbind.x86_64 0:0.2.0-11.el6

Complete!

[root@test ~]# yum install xinetd
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: centos.aol.in
 * extras: centos.aol.in
 * updates: centos.aol.in
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package xinetd.x86_64 2:2.3.14-38.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================
 Package                 Arch                    Version                          Repository             Size
==============================================================================================================
Installing:
 xinetd                  x86_64                  2:2.3.14-38.el6                  base                  121 k

Transaction Summary
==============================================================================================================
Install       1 Package(s)

Total download size: 121 k
Installed size: 259 k
Is this ok [y/N]:
requested URL returned error: 403"                                                                           
Trying other mirror.                                                                                          
rpcbind-0.2.0-11.el6.x86_64.rpm                                                        |  51 kB     00:00     
Running rpm_check_debug                                                                                       
Running Transaction Test                                                                                      
Transaction Test Succeeded                                                                                    
Running Transaction                                                                                           
  Updating   : rpcbind-0.2.0-11.el6.x86_64                                                                1/2 
  Cleanup    : rpcbind-0.2.0-9.el6.x86_64                                                                 2/2 
  Verifying  : rpcbind-0.2.0-11.el6.x86_64                                                                1/2 
  Verifying  : rpcbind-0.2.0-9.el6.x86_64                                                                 2/2 

Updated:
  rpcbind.x86_64 0:0.2.0-11.el6                                                                               

Complete!
[root@test ~]# yum install xinetd
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: centos.aol.in                    
 * extras: centos.aol.in                  
 * updates: centos.aol.in                 
Setting up Install Process                
Resolving Dependencies                    
--> Running transaction check             
---> Package xinetd.x86_64 2:2.3.14-38.el6 will be installed
--> Finished Dependency Resolution                          

Dependencies Resolved

==============================================================================================================
 Package                 Arch                    Version                          Repository             Size 
==============================================================================================================
Installing:                                                                                                   
 xinetd                  x86_64                  2:2.3.14-38.el6                  base                  121 k 

Transaction Summary
==============================================================================================================
Install       1 Package(s)

Total download size: 121 k
Installed size: 259 k
Is this ok [y/N]: y
Downloading Packages:
http://centos.aol.in/6.4/os/x86_64/Packages/xinetd-2.3.14-38.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 403"
Trying other mirror.
xinetd-2.3.14-38.el6.x86_64.rpm                                                        | 121 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 2:xinetd-2.3.14-38.el6.x86_64                                                              1/1
  Verifying  : 2:xinetd-2.3.14-38.el6.x86_64                                                              1/1

Installed:
  xinetd.x86_64 2:2.3.14-38.el6

Complete!

[root@test ~]# locate portmap                                       
/etc/selinux/targeted/modules/active/modules/portmap.pp                 
/usr/share/man/man8/portmap_selinux.8.gz                                
/usr/share/selinux/devel/include/services/portmap.if                    
/usr/share/selinux/targeted/portmap.pp.bz2                              
/usr/src/kernels/2.6.32-279.22.1.el6.x86_64/include/asm-generic/libata-portmap.h
/var/cache/rpcbind/portmap.xdr
[root@test ~]# /etc/init.d/portreserve start
Starting portreserve:
[root@test ~]# /etc/init.d/portreserve status
portreserve (pid  1590) is running...
[root@test ~]# /etc/init.d/xinetd start
Starting xinetd:                                           [  OK  ]
[root@test ~]# rpm -qa | grep bind
bind-utils-9.8.2-0.10.rc1.el6.x86_64
rpcbind-0.2.0-11.el6.x86_64
bind-libs-9.8.2-0.10.rc1.el6.x86_64
ypbind-1.20.4-29.el6.x86_64
samba-winbind-clients-3.5.10-125.el6.x86_64
[root@test ~]# service nfs restart
Shutting down NFS daemon:                                  [FAILED]
Shutting down NFS mountd:                                  [FAILED]
Shutting down NFS quotas:                                  [FAILED]
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Stopping RPC idmapd:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
[root@test ~]#
 restart nfs daemons with exportfs 

[root@test ~]# exportfs -r
[root@test ~]# chkconfig portreserve on
[root@test ~]# chkconfig nfs on
[root@test ~]# chkconfig xinetd on
[root@test ~]# mkdir /crush
[root@test ~]# chmod 777 /crush
[root@test ~]# vi /etc/exports
hare data folder for the network of 192.168.0.254/24 with read and write access
editing in exports
/crush 192.168.10.0/24(rw,rsync)

[root@test ~]# exportfs -r
[root@test ~]# showmount -e
Export list for test.example.net:
/crush 192.168.10.0/24

client side
 [root@test2 ~]# mount -t nfs 192.168.10.22:/crush /temp

[root@test2 ~]# cd /temp/
[root@test2 temp]# touch > test
touch: missing file operand
Try `touch --help' for more information.
[root@test2 temp]# cat > test
this is created for the nfs test
[root@test2 temp]#


to make the mount permanent. 

vi /etc/fstab

192.168.10.22  /temp nfs  default 0 0 

add this line and save it 


check the file created in client is available at server 

[root@test ~]# cd /crush/
[root@test crush]# ls
test
[root@test crush]# cat test
this is created for the nfs test