Friday, March 2, 2018

UNIX: check CPU usage and disk usage

Script to check cpu usage

grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'

#!/bin/bash

limit=2
email_destination="whatever@gmail.com"
email_body="WARNING the CPU usage on server `hostname` exceeded the limit you set ($limit)%"
email_subject="WARNING cpu usage"

usage=`grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}' | bc`

if echo $usage $limit | awk '{exit $1>$2?0:1}'
then
  echo -e $email_body | mail -s "$email_subject" $email_destination
  #echo 'alarm'
fi
_____________________________________________________

Disk space not updating in linux df -h after deleted files

ls -ld /proc/*/fd/* 2>&1 | fgrep '(deleted)'


restart the process that hold it

UNIX: sum and print total content of file

$ cat tpsCCRT.txt | awk '{sum+=$1} END {print "Count: ",NR;print "Avg :",sum/NR}'
Count:  1441
Avg : 15.6232
$

LinuxL Find file with certain permission


[root]# ls -l `find . -type f ! -perm 0755`
-rw-rw-r-- 1 root root    32550 Jan 18 14:20 ./centric_crm_tools-5.0.jar
-rw-rw-r-- 1 root root     8917 Jan 18 14:20 ./centric-troubleticketer-21.0.3.jar
-rw-rw-r-- 1 root root    10725 Jan 18 13:50 ./jdhcp-1.2.0.jar
-rw-rw-r-- 1 root root   228516 Jan 18 13:41 ./jradius-core-1.1.5.jar
-rw-rw-r-- 1 root root  4788404 Jan 18 13:41 ./jradius-dictionary-1.1.5.jar
-rw-r--r-- 1 root root    18289 Jan 18 13:51 ./opennms-alarm-northbounder-jms-21.0.3.jar
-rw-rw-r-- 1 root root    50911 Jan 18 13:51 ./opennms-dns-provisioning-adapter-21.0.3.jar
-rw-rw-r-- 1 root root    45429 Jan 18 13:49 ./opennms-integration-otrs-21.0.3.jar
-rw-rw-r-- 1 root root    60857 Jan 18 13:49 ./opennms-integration-otrs-31-21.0.3.jar
-rw-rw-r-- 1 root root     6037 Jan 18 13:49 ./opennms-integration-otrs-common-21.0.3.jar
-rw-rw-r-- 1 root root     7792 Jan 18 13:49 ./opennms-integration-rt-21.0.3.jar
-rw-r--r-- 1 root root 35841272 Jan 18 14:02 ./opennms_jmx_config_generator.jar
-rw-rw-r-- 1 root root   368488 Jan 18 13:51 ./opennms-rancid-provisioning-adapter-21.0.3.jar
-rw-rw-r-- 1 root root    49068 Jan 18 13:51 ./opennms-reverse-dns-provisioning-adapter-21.0.3.jar
-rw-rw-r-- 1 root root    54680 Jan 18 13:51 ./opennms-snmp-asset-provisioning-adapter-21.0.3.jar
-rw-rw-r-- 1 root root    55477 Jan 18 13:51 ./opennms-snmp-hardware-inventory-provisioning-adapter-21.0.3.jar
-rw-rw-r-- 1 root root    11951 Jan 18 13:51 ./opennms-vtdxml-collector-handler-21.0.3.jar
-rw-rw-r-- 1 root root  1871026 Jan 18 13:41 ./org.opennms.dependencies.jradius-extended-21.0.3.jar
-rw-rw-r-- 1 root root    22018 Jan 18 13:47 ./org.opennms.features.juniper-tca-collector-21.0.3.jar
-rw-r--r-- 1 root root    23005 Jan 18 13:50 ./org.opennms.features.ncs.ncs-drools-21.0.3.jar
-rw-r--r-- 1 root root    19288 Jan 18 13:50 ./org.opennms.features.ncs.ncs-northbounder-21.0.3.jar
-rw-r--r-- 1 root root    25031 Jan 18 13:45 ./org.opennms.features.ncs.ncs-persistence-21.0.3.jar
-rw-rw-r-- 1 root root     9602 Jan 18 13:51 ./org.opennms.protocols.cifs-21.0.3.jar
-rw-rw-r-- 1 root root    41591 Jan 18 13:50 ./org.opennms.protocols.dhcp-21.0.3.jar
-rw-rw-r-- 1 root root    63485 Jan 18 13:50 ./org.opennms.protocols.nsclient-21.0.3.jar
-rw-rw-r-- 1 root root    25416 Jan 18 13:50 ./org.opennms.protocols.radius-21.0.3.jar
-rw-rw-r-- 1 root root    47068 Jan 18 13:50 ./org.opennms.protocols.xmp-21.0.3.jar
-rw-rw-r-- 1 root root   637560 Jan 18 13:51 ./vtd-xml-2.11.jar
-rw-rw-r-- 1 root root    88198 Jan 18 13:50 ./xmp-1.40.jar
[root]#

Friday, May 26, 2017

Unix: Find list of files in gz format contain strings

$ find . -name "*.gz" -exec zgrep -la bbarney03@xxxx.com \{\} \;
./aaa_1/231_20160606193002_232895_330_20160606_231655_1_0000_01.act.gz
./aaa_1/231_20160606173001_604598_330_20160606_211628_1_0000_01.act.gz
./aaa_1/232_20160606191508_769207_935_20160606_230502_1_0000.act.gz
./aaa_1/232_20160606191600_522897_329_20160606_230518_1_0000.act.gz
./aaa_1/232_20160606160002_239869_935_20160606_194946_1_0000.act.gz
./aaa_1/232_20160606094601_736357_329_20160606_133804_1_0000.act.gz
./aaa_1/232_20160606103002_77028_935_20160606_141917_1_0000.act.gz
./aaa_1/231_20160606113107_109722_840_20160606_152107_1_0000.act.gz
./aaa_1/231_20160606120002_183644_330_20160606_154014_1_0000_03.act.gz
./aaa_1/231_20160606094501_813187_330_20160606_133446_1_0000_00.act.gz
./aaa_1/232_20160606114501_577769_935_20160606_153424_1_0000.act.gz
./aaa_1/232_20160606104600_643312_329_20160606_143819_1_0000.act.gz
./aaa_1/232_20160606103107_699907_837_20160606_141919_1_0000.act.gz
./aaa_1/231_20160606120019_863535_330_20160606_154515_1_0000_01.act.gz
./aaa_1/232_20160606094701_251538_329_20160606_133804_1_0000_03.act.gz
./aaa_1/232_20160606153002_294217_935_20160606_191943_1_0000.act.gz
./aaa_1/232_20160606160107_988588_837_20160606_194949_1_0000.act.gz
./aaa_1/232_20160606160102_442949_329_20160606_195433_1_0000.act.gz
./aaa_1/232_20160606114603_483834_837_20160606_153426_1_0000.act.gz
./aaa_1/231_20160606153002_218144_330_20160606_191602_1_0000_02.act.gz

$ zgrep -i bbarney03@xxxx.com 231_20160609122102_492219_840_20160609_160748_1_0000.act.gz

$ zgrep -la bbarney03@sxxxxcom 231_20160609122102_492219_840_20160609_160748_1_0000.act.gz

find . -name "*.gz" -exec zgrep -la 8434763502 \{\} \;
find . -name "*.gz" -exec zgrep -la 50495939382 \{\} \;

Wednesday, May 28, 2014

Linux: find hba information

-bash-3.2$ nsu
Password:
[root@redhat ~]# cd /opt/hp
[root@redhat hp]# ls
hpdiags        hp-ilo       hpsmh             hpssa
hp_fibreutils  hpmouse      hp-smh-templates  hpssacli
hp-health      hp-OpenIPMI  hp-snmp-agents
[root@redhat hp]# cd hp_fibreutils
[root@redhat hp_fibreutils]# ls
adapter_info  hp_rescan  lssd  lssg  scsi_info
[root@redhat hp_fibreutils]# ./hp_rescan -h
NAME

hp_rescan

DESCRIPTION

Sends the rescan signal to all or selected Fibre Channel HBAs/CNAs.

OPTIONS

-a, --all      - Rescan all Fibre Channel HBAs
-h, --help     - Prints this help message
-i, --instance - Rescan a particular instance
-l, --list     - List all supported Fibre Channel HBAs
[root@redhat hp_fibreutils]# ./hp_rescan -l
QLogic adapters:

/sys/class/scsi_host/1
/sys/class/scsi_host/2

Emulex adapters:


Brocade adapters:

[root@redhat hp_fibreutils]# cd /sys/class/scsi_host
[root@redhat scsi_host]# ls
host0  host1  host2
[root@redhat scsi_host]# ls -la
total 0
drwxr-xr-x  5 root root 0 May 23 14:25 .
drwxr-xr-x 43 root root 0 May 23 14:26 ..
drwxr-xr-x  2 root root 0 May 26 11:13 host0
drwxr-xr-x  2 root root 0 May 26 11:13 host1
drwxr-xr-x  2 root root 0 May 26 11:13 host2
[root@redhat scsi_host]# cd host1
[root@redhat host1]# ls
84xx_fw_version   model_desc            state
beacon            model_name            subsystem
cmd_per_lun       mpi_version           total_isp_aborts
device            npiv_vports_inuse     uevent
driver_version    optrom_bios_version   unchecked_isa_dma
fabric_param      optrom_efi_version    unique_id
flash_block_size  optrom_fcode_version  vlan_id
fw_dump_size      optrom_fw_version     vn_port_mac_address
fw_state          pci_info              vport_create
fw_version        phy_version           vport_delete
host_busy         proc_name             zio
isp_id            scan                  zio_timer
isp_name          serial_num
max_npiv_vports   sg_tablesize
[root@redhat host1]# more driver_version
8.04.00.12.5.6-k2
[root@redhat host1]# more model_name
QMH2462
[root@redhat host1]#

Thursday, March 20, 2014

Solaris: nvalias

# format
Searching for disks...done


AVAILABLE DISK SELECTIONS:
       0. c1t0d0
          /pci@0/pci@0/pci@2/scsi@0/sd@0,0
       1. c1t1d0
          /pci@0/pci@0/pci@2/scsi@0/sd@1,0
       2. c4t60060E80056F110000006F11000060D4d0
          /scsi_vhci/ssd@g60060e80056f110000006f11000060d4
Specify disk (enter its number):


{0} ok printenv boot-device
boot-device =           /pci@0/pci@0/pci@2/scsi@0/disk@0,0:a disk net
{0} ok nvalias root-mirr /pci@0/pci@0/pci@2/scsi@0/disk@1,0:a
{0} ok devalias
root-mirr                /pci@0/pci@0/pci@2/scsi@0/disk@1,0:a
ttya                     /ebus@c0/serial@0,ca0000
nvram                    /virtual-devices/nvram@3
net3                     /pci@0/pci@0/pci@1/pci@0/pci@3/network@0,1
net2                     /pci@0/pci@0/pci@1/pci@0/pci@3/network@0
net1                     /pci@0/pci@0/pci@1/pci@0/pci@2/network@0,1
net0                     /pci@0/pci@0/pci@1/pci@0/pci@2/network@0
net                      /pci@0/pci@0/pci@1/pci@0/pci@2/network@0
cdrom                    /pci@0/pci@0/pci@1/pci@0/pci@1/pci@0/usb@0,2/hub@4/device@4/storage@0/disk@0:f
disk3                    /pci@0/pci@0/pci@2/scsi@0/disk@3
disk2                    /pci@0/pci@0/pci@2/scsi@0/disk@2
disk1                    /pci@0/pci@0/pci@2/scsi@0/disk@1
disk0                    /pci@0/pci@0/pci@2/scsi@0/disk@0
disk                     /pci@0/pci@0/pci@2/scsi@0/disk@0
scsi                     /pci@0/pci@0/pci@2/scsi@0
virtual-console          /virtual-devices/console@1
name                     aliases
{0} ok boot

HPUX: How to check hpux ilo firmware version

<>hpiLO-> show
status=0
status_tag=COMMAND COMPLETED


/
  Targets
    system1
    map1
  Properties
  Verbs
    cd version exit show


<>hpiLO-> show /map1

status=0
status_tag=COMMAND COMPLETED


/map1
  Targets
    firmware1
    accounts1
    log1
    enetport1
    dhcpendpt1
    dnsendpt1
    gateway1
    dnsserver1
    dnsserver2
    dnsserver3
    dhcpserver1
    settings1
    config1
    snmp1
    oemhp_dircfg1
    oemhp_vm1
    vlan1
    oemhp_ssocfg1
  Properties
    name=iLO 3 Advanced
    license=3368NY7M2BQGKTNMLDZ8KZLLH
  Verbs
    cd version exit show reset set oemhp_ping



hpiLO-> show firmware1
status=0
status_tag=COMMAND COMPLETED


/map1/firmware1
  Targets
  Properties
    version=1.10
    date=Jul 26 2010
  Verbs
    cd version exit show load set



hpiLO->

to upgrade


How to upgrade the firmware using SSH PDF Print E-mail
Written by Carlo Cacciafesta  
Thursday, 07 January 2010 13:35
How to upgrade the firmware using SSH

The following commands can be used to upgrade the firmware on an HP iLO or iLO2 interface. This procedure is particularly useful when the iLO stops working properly and it's not accessible from the server or via HTTP(S).

Use the following procedure:

    * Use SSH to access the iLO device
    * Log in to the iLO using administrative credentials
    * Type the following command and press enter: "load -source http://ip_address/path/imagename.bin /map1/firmware"
          o  Example: "load -source http://192.168.0.1/ilo2_180.bin /map1/firmware"
    * The interface will download the new image and will reset itself
    * To check the firmware version, log in again using SSH and enter the following command: "show /map1/firmware version"

UNIX: How to print column nicely using printf

[user@hostfwnms1-oam tmp]# cat b.sh printf "%-26s %-19s %-8s %-8s %-s %-s\n" HOSTNAME IP PING SNMPWALK 0-ok 1-fail for i in `cat n...