Wednesday, March 8, 2017

recursive function shell script for File System Monitoring

/opt/newdir file system is 92% full and we want to send an email to root once it goes above 90%

[root@dns1 shellscripts]# df -h /opt/newdir/
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/lvm--raid-myvol01
                       97M   84M  7.9M  92% /opt/newdir

[root@dns1 shellscripts]# df -h /opt/newdir/ | awk '{print $4}' | grep -v "Avail" | sed 's/%$//'


92

[root@dns1 shellscripts]# cat recursive_functions.sh

#!/bin/bash
# define first function
my_one() {
        monitor_new_dir=`df -h /opt/newdir/ | awk '{print $4}' | grep -v "Avail" | sed 's/%$//'`
        size=90
        if [ $size -lt $monitor_new_dir ]
        then
        echo "Filesystem is $monitor_new_dir% full. Please take action"| mail -s "Do the clean up now" root
        else
        echo "You are good"
        fi
        my_two
}
my_two() {
        echo This is second function
}

my_one

             
             

Here is the OutPut:

[root@dns1 shellscripts]# ./recursive_functions.sh
This is second function
[root@dns1 shellscripts]# mail
  600 root                  Sat Mar  4 11:04  21/803   "Do the clean up now"
>N601 root                  Sat Mar  4 11:05  21/787   "Do the clean up now"
& 601
Message 601:
From root@dns1.example.com  Sat Mar  4 11:05:02 2017
Return-Path:
From: root
Date: Sat, 04 Mar 2017 11:05:02 -0800
To: root@dns1.example.com
Subject: Do the clean up now
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
Status: R

Filesystem is 92% full. Please take action

Sunday, March 5, 2017

Nestat socket states - from man page reference

[root@puppet-agent1 shellscript]# netstat -tulpn

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1946/sshd          
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1807/cupsd        
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2076/master        
tcp        0      0 :::22                       :::*                                 LISTEN      1946/sshd          
tcp        0      0 ::1:631                     :::*                        LISTEN      1807/cupsd        
tcp        0      0 ::1:25                      :::*                        LISTEN      2076/master        
udp        0      0 0.0.0.0:631                 0.0.0.0:*                               1807/cupsd        
udp        0      0 0.0.0.0:68                  0.0.0.0:*                               1772/dhclient      


    Recv-Q
       The count of bytes not copied by the user program connected to this socket.

   Send-Q
       The count of bytes not acknowledged by the remote host.

   Local Address
       Address and port number of the local end of the socket.  Unless the --numeric (-n) option is         specified, the socket address is resolved
       to its canonical host name (FQDN), and the port number is translated into the corresponding service name.

   Foreign Address
       Address and port number of the remote end of the socket.  Analogous to "Local Address."


       The state of the socket. Since there are no states in raw mode and usually no states used in UDP, this column may be left blank.  Normally this can be one of several values:

       ESTABLISHED
              The socket has an established connection.

       SYN_SENT
              The socket is actively attempting to establish a connection.

       SYN_RECV
              A connection request has been received from the network.

       FIN_WAIT1
              The socket is closed, and the connection is shutting down.

       FIN_WAIT2
              Connection is closed, and the socket is waiting for a shutdown from the remote end.

       TIME_WAIT
              The socket is waiting after close to handle packets still in the network.

       CLOSED
 The socket is not being used.

       CLOSE_WAIT
              The remote end has shut down, waiting for the socket to close.

       LAST_ACK
              The remote end has shut down, and the socket is closed. Waiting for acknowledgement.

       LISTEN 
The socket is listening for incoming connections.  Such sockets are not included in the output unless you specify the --listen option.

       CLOSING
              Both sockets are shut down but we still don't have all our data sent.

       UNKNOWN
              The state of the socket is unknown.


Saturday, March 4, 2017

puppet agent installation on Centos 6.5

First enable the puppet repository by installing the puppetlabs-release-6-10.noarch.rpm package

[root@puppet-agent ~]# rpm -ivh https://yum.puppetlabs.com/el/6.5/products/x86_64/puppetlabs-release-6-10.noarch.rpm
Retrieving https://yum.puppetlabs.com/el/6.5/products/x86_64/puppetlabs-release-6-10.noarch.rpm
warning: /var/tmp/rpm-tmp.FD1UUR: Header V4 RSA/SHA1 Signature, key ID 4bd6ec30: NOKEY
Preparing...                ########################################### [100%]
   1:puppetlabs-release     ########################################### [100%]
[root@puppet-agent ~]# yum install puppet
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.gbeservers.com
 * extras: mirrors.usinternet.com
 * updates: centos-distro.cavecreek.net
puppetlabs-deps                                                                                                                       | 2.5 kB     00:00    
puppetlabs-deps/primary_db                                                                                                            |  27 kB     00:00    
puppetlabs-products                                                                                                                   | 2.5 kB     00:00    
puppetlabs-products/primary_db                                                                                                        | 170 kB     00:00    
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package puppet.noarch 0:3.8.7-1.el6 will be installed
--> Processing Dependency: ruby >= 1.8.7 for package: puppet-3.8.7-1.el6.noarch
--> Processing Dependency: ruby >= 1.8 for package: puppet-3.8.7-1.el6.noarch


Out put truncated .....

[root@puppet-agent ~]# puppet --version
3.8.7

Configuration:

1. In the main section of the puppet.conf

[root@puppet-agent ~]# vi /etc/puppet/puppet.conf

[main]
    # The Puppet log directory.
    # The default value is '$vardir/log'.
    logdir = /var/log/puppet
    server = skywalker.example.com


2. Allow the firewall on port 8140 or disable it if you are just testing the puppet

3. Generate the client cert

[root@puppet-agent ~]# puppet agent -t
Info: Creating a new SSL key for puppet-agent.example.com
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for puppet-agent.example.com
Info: Certificate Request fingerprint (SHA256): 57:C0:26:83:1D:20:FB:46:03:91:50:47:12:CE:41:CE:D0:56:06:40:D8:E6:A7:67:D4:FD:E4:10:A0:AD:F8:E6
Info: Caching certificate for ca
Exiting; no certificate found and waitforcert is disabled

4. ignore the error for "waitforcecert" we yet have to sign the client from the puppet master

[root@puppet-agent ~]# puppet cert list
Notice: Signed certificate request for ca

5. Display the cert from master 

[root@skywalker puppet]# puppet cert list -a
  "puppet-agent.example.com"               (SHA256) 57:C0:26:83:1D:20:FB:46:03:91:50:47:12:CE:41:CE:D0:56:06:40:D8:E6:A7:67:D4:FD:E4:10:A0:AD:F8:E6

6. Cert is signed now

 [root@skywalker puppet]# puppet cert sign puppet-agent.example.com
Signing Certificate Request for:
  "puppet-agent.example.com" (SHA256) 57:C0:26:83:1D:20:FB:46:03:91:50:47:12:CE:41:CE:D0:56:06:40:D8:E6:A7:67:D4:FD:E4:10:A0:AD:F8:E6
Notice: Signed certificate request for puppet-agent.example.com
Notice: Removing file Puppet::SSL::CertificateRequest puppet-agent.example.com at '/etc/puppetlabs/puppet/ssl/ca/requests/puppet-agent.example.com.pem'

7. now run - puppet agent -t 

[root@puppet-agent ~]# puppet agent -t
Info: Caching certificate for puppet-agent.example.com
Info: Caching certificate_revocation_list for ca
Info: Caching certificate for puppet-agent.example.com

output truncated ....

puppet agent is seen in the inventory of the puppet master to manage.




Thanks.


Friday, March 3, 2017

puppet agent Cert error - No route to the host

after installing the agent and trying to register the cert with the master server got the following error:

Resolution : Either allow client via firewall so that puppet master can talk to the client and vice versa
or stop the firewall and the error should go away.

Error: Could not request certificate: No route to host - connect(2)

Friday, February 24, 2017

Centos 7 new logical volume

[root@centos7 ~]# uname -a
Linux centos7.example.com 3.10.0-327.el7.i686 #

[root@centos7 ~]# vgs
  VG         #PV #LV #SN Attr   VSize  VFree
  cl_centos7   1   2   0 wz--n- 19.51g 40.00m

[root@centos7 ~]# lvcreate  -L 10M -n vol01 cl_centos7
  Rounding up size to full physical extent 12.00 MiB
  Logical volume "vol01" created.

[root@centos7 ~]# lvs
  LV    VG         Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root  cl_centos7 -wi-ao---- 17.47g
  swap  cl_centos7 -wi-ao----  2.00g
  vol01 cl_centos7 -wi-a----- 12.00m

[root@centos7 ~]# mkdir /devops01

[root@centos7 ~]# mkfs.ext4 /dev/cl_centos7/vol01
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
3072 inodes, 12288 blocks
614 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=12582912
2 block groups
8192 blocks per group, 8192 fragments per group
1536 inodes per group
Superblock backups stored on blocks:
        8193
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

[root@centos7 ~]# mount /dev/cl_centos7/vol01 /devops01/

[root@centos7 ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/cl_centos7-root    18G  4.7G   13G  27% /
/dev/mapper/cl_centos7-vol01   11M  204K  9.6M   3% /devops01






Tuesday, November 1, 2016

eth0 interface not found after restoring VM

eth0 interface not found after restoring rhel6 - So when the machine completed the restoring eth0 was was missing but the /etc/sysconfig/network-scripts file was still there. Found out that the configuration of the file changed to something like this -








Changed the above setting to the following -



After service network restart and the issue was fixed!

Tuesday, July 21, 2015

lspci equivalent in solaris world.


* lspci output from linux to displays all information from the PCI busses on your Linux system and all the devices connected to the busses.


testlab01# lspci
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01)
00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)
00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
00:11.0 PCI bridge: VMware PCI bridge (rev 02)
00:15.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.3 PCI bridge: VMware PCI Express Root Port (rev 01)

................... Output truncated

I was just wondering if there is equivalent of lspci in solaris world! Here it is with the partial output as the command throws
all the devices information from the PCI buses. The location of the binary is - /usr/X11/bin/scanpci

solarislab01#  /usr/X11/bin/scanpci

pci bus 0x0000 cardnum 0x01 function 0x00: vendor 0x108e device 0x8186
 Oracle/SUN Device unknown

pci bus 0x0000 cardnum 0x02 function 0x00: vendor 0x108e device 0x8186
 Oracle/SUN Device unknown

pci bus 0x0001 cardnum 0x00 function 0x00: vendor 0x111d device 0x807a
 Integrated Device Technology, Inc. Device unknown

pci bus 0x0003 cardnum 0x00 function 0x00: vendor 0x108e device 0xabcd
 Oracle/SUN Multithreaded 10-Gigabit Ethernet Network Controller

pci bus 0x0003 cardnum 0x00 function 0x01: vendor 0x108e device 0xabcd
 Oracle/SUN Multithreaded 10-Gigabit Ethernet Network Controller

pci bus 0x0003 cardnum 0x00 function 0x02: vendor 0x108e device 0xabcd
 Oracle/SUN Multithreaded 10-Gigabit Ethernet Network Controller

pci bus 0x0003 cardnum 0x00 function 0x03: vendor 0x108e device 0xabcd
 Oracle/SUN Multithreaded 10-Gigabit Ethernet Network Controller

pci bus 0x0004 cardnum 0x00 function 0x00: vendor 0x1000 device 0x0072
 LSI Logic / Symbios Logic SAS2008 PCI-Express Fusion-MPT SAS-2 [Falcon]

pci bus 0x0005 cardnum 0x00 function 0x00: vendor 0x108e device 0xabcd
 Oracle/SUN Multithreaded 10-Gigabit Ethernet Network Controller

pci bus 0x0005 cardnum 0x00 function 0x01: vendor 0x108e device 0xabcd
 Oracle/SUN Multithreaded 10-Gigabit Ethernet Network Controller

pci bus 0x0005 cardnum 0x00 function 0x02: vendor 0x108e device 0xabcd
 Oracle/SUN Multithreaded 10-Gigabit Ethernet Network Controller

pci bus 0x0005 cardnum 0x00 function 0x03: vendor 0x108e device 0xabcd
 Oracle/SUN Multithreaded 10-Gigabit Ethernet Network Controller

pci bus 0x0006 cardnum 0x00 function 0x00: vendor 0x10df device 0xfc40
 Emulex Corporation Saturn-X: LightPulse Fibre Channel Host Adapter

pci bus 0x0006 cardnum 0x00 function 0x01: vendor 0x10df device 0xfc40
 Emulex Corporation Saturn-X: LightPulse Fibre Channel Host Adapter

pci bus 0x0007 cardnum 0x00 function 0x00: vendor 0x111d device 0x8077
 Integrated Device Technology, Inc. Device unknown

pci bus 0x0008 cardnum 0x00 function 0x00: vendor 0x111d device 0x8077
 Integrated Device Technology, Inc. Device unknown

pci bus 0x0008 cardnum 0x04 function 0x00: vendor 0x111d device 0x8077
 Integrated Device Technology, Inc. Device unknown

pci bus 0x0008 cardnum 0x06 function 0x00: vendor 0x111d device 0x8077
 Integrated Device Technology, Inc. Device unknown

pci bus 0x0008 cardnum 0x07 function 0x00: vendor 0x111d device 0x8077
 Integrated Device Technology, Inc. Device unknown

pci bus 0x0008 cardnum 0x08 function 0x00: vendor 0x111d device 0x8077
 Integrated Device Technology, Inc. Device unknown

pci bus 0x0008 cardnum 0x0a function 0x00: vendor 0x111d device 0x8077
 Integrated Device Technology, Inc. Device unknown

pci bus 0x0008 cardnum 0x0c function 0x00: vendor 0x111d device 0x8077
 Integrated Device Technology, Inc. Device unknown

pci bus 0x0008 cardnum 0x0f function 0x00: vendor 0x111d device 0x8077
 Integrated Device Technology, Inc. Device unknown

pci bus 0x0009 cardnum 0x00 function 0x00: vendor 0x1a03 device 0x1150
 ASPEED Technology, Inc. AST1150 PCI-to-PCI Bridge

pci bus 0x000a cardnum 0x00 function 0x00: vendor 0x1a03 device 0x2000
 ASPEED Technology, Inc. ASPEED Graphics Family

pci bus 0x000b cardnum 0x00 function 0x00: vendor 0x1000 device 0x0072
 LSI Logic / Symbios Logic SAS2008 PCI-Express Fusion-MPT SAS-2 [Falcon]

pci bus 0x000c cardnum 0x00 function 0x00: vendor 0x8086 device 0x10c9
 Intel Corporation 82576 Gigabit Network Connection

pci bus 0x000c cardnum 0x00 function 0x01: vendor 0x8086 device 0x10c9
 Intel Corporation 82576 Gigabit Network Connection

pci bus 0x000d cardnum 0x00 function 0x00: vendor 0x8086 device 0x10c9
 Intel Corporation 82576 Gigabit Network Connection

pci bus 0x000d cardnum 0x00 function 0x01: vendor 0x8086 device 0x10c9
 Intel Corporation 82576 Gigabit Network Connection

pci bus 0x000e cardnum 0x00 function 0x00: vendor 0x10df device 0xfc40
 Emulex Corporation Saturn-X: LightPulse Fibre Channel Host Adapter

pci bus 0x000e cardnum 0x00 function 0x01: vendor 0x10df device 0xfc40
 Emulex Corporation Saturn-X: LightPulse Fibre Channel Host Adapter

pci bus 0x0011 cardnum 0x00 function 0x00: vendor 0x10b5 device 0x8112
 PLX Technology, Inc. PEX8112 x1 Lane PCI Express-to-PCI Bridge

pci bus 0x0012 cardnum 0x00 function 0x00: vendor 0x1033 device 0x0035
 NEC Corporation USB

pci bus 0x0012 cardnum 0x00 function 0x01: vendor 0x1033 device 0x0035
 NEC Corporation USB

pci bus 0x0012 cardnum 0x00 function 0x02: vendor 0x1033 device 0x00e0
 NEC Corporation USB 2.0

device unknown is nothing but the device is not in use or attached. Once the device
is in use or active the details will be shown like ex. NEC Corporation USB 2.0 as above.

Thanks.