Wednesday, August 31, 2016

linux usual Cmds



history Command with timestamp
HISTTIMEFORMAT="%d/%m/%y %T "
history 200

grep  usage examples 
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_02.html

=============================
Change  root password expiry 
# chage -l root  (that is a lower case L)
# chage -I 1 -m 0 -M 99999 root
====================================================
systemctl is-active application.service
systemctl status application.service
systemctl is-enabled application.service
systemctl is-failed application.service

systemctl list-unit-files  |grep enabled
systemctl list-units --all
systemctl list-units --all --state=inactive
systemctl list-units --type=service
systemctl cat atd.service
systemctl list-dependencies sshd.service
systemctl show sshd.service
systemctl show sshd.service -p Conflicts
https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
======================================================
yum  commands  usage
http://www.thegeekstuff.com/2011/08/yum-command-examples/?utm_source=feedburner
https://www.tecmint.com/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement/

-------------------------------------------------------------------------------------
fuser  command 
How To View Processes Using A Directory
fuser -v /opt/cdu
displays all processes accessing filesystem on which ‘example.txt’ resides.
fuser -v -m example.txt
To list the process numbers and users of processes of a file
fuser -u  /etc/magic
To terminate all of the processes using a given file system,
fuser -k -x -u -c /dev/hd1
fuser -kxuc /home
fuser -kuc /u/home/code

To list all processes that are using a file which has been deleted from a given file system,
fuser -d /usr
What process is using your tcp or udp socket?
fuser -v -n tcp 80
Kill Processes that are Using a particular Program
fuser -v -k socket_serv
fuser -v -k -i socket_serv   -->asking permission to kill

# yum search fuser
psmisc.x86_64 : Utilities for managing processes on your system
======================================================================
To make nfs export in  linux
http://www.redhat.com/docs/manuals/linux/RHL-7.2-Manual/custom-guide/nfs-export.html
NFS  /etc/exports Configuration File
https://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-nfs-server-config-exports.html
to make an nfs export make entry in  /etc/exports 
/EMRBCP   cpvra00a0024(rw,no_all_squash,no_root_squash
/another/exported/directory 192.168.0.3(rw,sync)
/mnt/export speedy.redhat.com(rw)
#service nfs  restart
#exportfs   -r
#/sbin/service nfs start

Make NFS mount  in /etc/fstab
#-#  NAS nfs mount
wfsaloxnsf01.ent.com:/vol/vol90    /app/nfsdocuments    nfs   rw,bg,hard,rsize=32768,wsize=32768,vers=3,actimeo=0,nointr,nosuid,timeo=600,tcp    0 0  

Make NFS mount in command line
mount -t nfs -o ro  server_IP_addr:/share_name /local_mount_point

showmount -e   -->  to see nfs  shares of  a server

to see mounts and properties 
findmnt - find a filesyst
[root@ruvra89a0047 ~]# findmnt
TARGET                       SOURCE                  FSTYPE      OPTIONS
/                            /dev/mapper/system-root ext4        rw,relatime,barrier=1,data=ordered
â"œâ"€/proc                      proc                    proc        rw,relatime
â"‚ â"œâ"€/proc/bus/usb            /proc/bus/usb           usbfs       rw,relatime
â"‚ â""â"€/proc/sys/fs/binfmt_misc                         binfmt_misc rw,relatime
â"œâ"€/sys                       sysfs                   sysfs       rw,relatime
â"œâ"€/dev                       devtmpfs                devtmpfs    rw,relatime,size=8087064k,nr_inodes=2021766,mode=755
â"‚ â"œâ"€/dev/pts                 devpts                  devpts      rw,relatime,gid=5,mode=620,ptmxmode=000
â"‚ â""â"€/dev/shm                 tmpfs                   tmpfs       rw,relatime
â"œâ"€/boot                      /dev/sda1               ext4        rw,relatime,barrier=1,data=ordered
â""â"€/home                      /dev/mapper/system-home ext4        rw,nosuid,nodev,relatime,barrier=1,data=ordered

[root@ruvra89a0047 ~]# blkid
/dev/mapper/system-root: UUID="5574eebc-631c-438e-ad6a-27afff176519" TYPE="ext4"
/dev/sda1: UUID="c481e46c-56f3-4b69-a03c-5987fa92efcc" TYPE="ext4"
/dev/sda2: UUID="xheITH-YMkP-3otM-5jvm-859E-ekIo-JcFRpQ" TYPE="LVM2_member"
/dev/mapper/system-swap: UUID="ee7e76ca-7e72-477c-8b8f-634c0038334c" TYPE="swap"
/dev/mapper/system-home: UUID="5e7fb8b8-95fe-48fa-86f4-8302ffdc1fb6" TYPE="ext4"

# df -Ph
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/system-root       54G   11G   41G  22% /
devtmpfs                     7.8G     0  7.8G   0% /dev
tmpfs                        7.8G     0  7.8G   0% /dev/shm
tmpfs                        7.8G  137M  7.6G   2% /run
tmpfs                        7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda1                    488M  202M  251M  45% /boot
/dev/mapper/system-home      240M  2.2M  221M   1% /home
======================================================================









Friday, August 12, 2016

redhat network Commands

copied it from linuxCmdNetwork.docx in laptop

===============Networking===============================
ifconfig -a
ifconfig eth1 up    --->  to activate eth1
ifconfig eth1 down    ---> to de activate the eth1
ifup bond1  ---->  to activate a bond
service network restart   ---->  to restart network service
service network status    ----->   status of the network devices
system-config-network  ---> command to configure the Ethernet

list the network  devices
lspci
lspci -tv
lspci |grep net
systool -c net
systool -c net -v |grep -v "00 00 00"|grep -v "0x000"
systool -c net -d eth6  -v |grep -v "00 00 00"|grep -v "0x000"

To see  speed of  a Interface
systool -c net -d eth6  -v |grep -v "00 00 00"|grep -v "0x000" |egrep "Class |speed"
systool -c net  -v |grep -v "00 00 00"|grep -v "0x000" |egrep "Class|speed"
grep -H .  /sys/class/net/*/speed
grep -H .  /sys/class/net/*/mtu

To  see  the   interface  and   network  slot  info
/opt/dell/srvadmin/bin/omreport  chassis  nics

2) to see  onboard  network ports using dmidecode
Use below command to see the BUS Address for Ethernet ports
dmidecode -t baseboard |egrep -i "Desig|Bus|type|status"
dmidecode -t baseboard |grep -B1 -A3 Ethernet |egrep -i "Desig|Bus|type|status"
Then use below command to see eth# in  each BUS
systool -c net
lspci -tv |grep net

3)To see PCI slot network ports using dmidecode
Use below command to see BUSAddress for PCI slots
            dmidecode -t slot |egrep "Desig|Bus|Current|Type"
Then use below command to see eth# in  each BUS
systool -c net
lspci -tv |grep net


To  assign ipaddress on  interface
ifconfig eth1  xx.xx.xx.xx  netmask  255.xxx.xxx.x  up
service network restart

$ cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=167.143.186.235
NETMASK=255.255.254.0
GATEWAY=167.143.186.1
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
# Added OPTS for RHEL6 (glh)
        BONDING_OPTS="miimon=100 mode=active-backup"

Set static route  via bond1  ip address
$ cat /etc/sysconfig/network-scripts/route-bond1
162.100.228.0/24  via   170.13.151.1  dev  bond1
130.29.230.0/24  via  170.13.151.1 dev bond1

Netstat command
netstat  -rn      >>  to see routing table       
route  -e      >>      to see routing table        
netstat  -in      >>  network statistics summary
netstat  -an     >>  this will list all ports and their status
cat  /proc/net/dev  >>  to see packet send/receive summary through diff interfaces

to See  ports Listening Status
            grep 9080  /etc/services
            glrpc           9080/tcp                # Groove GLRPC
            netstat -anp  |grep 9080
            netstat -an | grep 1002
            netstat -lpn  ==>  to list listening ports
            netstat -lpn  |grep 1002
            netstat  -tulpn  ==> tcp,udp  listening ports

     lsof -i tcp:1002
     lsof -i udp:1002
     lsof -i  :1002
     lsof  -i |grep  glrpc
     lsof |grep glrpc

 http://www.binarytides.com/linux-ss-command/    ss command  usage 
List all connections The simplest command is to list out all connections. $  ss  | less



change network interface names permanently in Linux
In /etc/udev/rules.d/70-persistent-net.rules, you can assign  device name to a particular MAC address.
find out the MAC address interface"grep -H . /sys/class/net/*/address"  , and then define the interface name to that MAC address in the following format.
# interface with MAC address "00:0c:29:43:28:11" will be assigned "eth0"                                                                            
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:43:28:11", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

To see if an interface  have connection 
ethtool eth2
Settings for eth1:
        Supports Wake-on: g
        Wake-on: d
        Link detected: yes 
mii-tool -v
eth0: negotiated, link ok


To enable Jumbo frames in Linux
To set temporary
# ifconfig eth0 mtu 9000
To Make changes permanent:-Edit the network configuration file for eth0 interface - /etc/sysconfig/network-scripts/ifcfg-eth0 (CentOS / RHEL / Fedora Linux):
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Append the following configuration directive, which specifies the size of the frame in bytes:
MTU 9000
 Restart the Interface eth0:
 /etc/init.d/network restart   or service network restart
To confirm the MTU used between two specific devices. use ip command as follows:
# ip route get {IP-address}
# ip route get 192.168.1.1
Do Ping Test
# ping   -s 8192   -I <source interconnect IP address> <destination IP address>
Example:
# ping -s 8192 -I 198.18.0.38 198.18.0.39




To see the bonds and the   related  network adapers
cd /proc/net/bonding
ls
cat bond0 
cd /sys/class/net/
[root@dansrzd180 net]# ls
bond0  bond1  eth0  eth1  eth2  eth3  lo  sit0



Steps to make BONDS
doc-7944    (how to make bond  RH3)
doc-8108    what are diff modes
how to make bond in RH4
http://kbase.redhat.com/faq/docs/DOC-4284
http://www.cyberciti.biz/tips/linux-bond-or-team-multiple-network-interfaces-nic-into-single-interface.html
http://et.redhat.com/~jmh/docs/Xen_networking.pdf


remember to make backup of files being changed  before editing
step1 :- update   /etc/modprobe.conf   with proper entties as below
vi /etc/modprobe.conf 
alias bond0 bonding
options bonding miimon=100 mode=1 max_bonds=2
install bond0 /sbin/modprobe bonding --ignore-install bonding
alias bond1 bonding
install  bond1 /sbin/modprobe bonding -o bond1

step2:  create fcfg-eth1,fcfg-eth3 and ifcfg-bond1  with simillar entries like below in /etc/sysconfig/network-scripts
[root@dansrzd180 network-scripts]# cat ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond1
SLAVE=yes
USERCTL=no
HWADDR=00:24:E8:64:62:53

[root@dansrzd180 network-scripts]# cat ifcfg-eth3
DEVICE=eth3
BOOTPROTO=none
ONBOOT=yes
MASTER=bond1
SLAVE=yes
USERCTL=no
HWADDR=00:15:17:BC:C5:BD

[root@dansrzd180 network-scripts]# cat ifcfg-bond1
DEVICE=bond1
IPADDR=10.28.130.40
NETMASK=255.255.255.0
GATEWAY=
ONBOOT=yes
BOOTPROTO=none
USERCTL=no

step3 :-
update  /etc/hosts  file with interconnect ipaddresses
restart the networks and bringup the bond1
modprobe bonding
service network restart
ifup bond1




Kernal Mudule Commands

lsmod |grep bond   
rmmod    modname
modprobe --show-depends bond1
depmod -a   (generate map files )
modprobe - program to add and remove modules from the Linux Kernel
  eg:-  modprobe  bonding  -o bond1
            ifconfig bond1 down  ; modprobe -r bond1

Configuring the Linux6 host for LACP bonding

step1:Linux Kernel Module Configuration

#/etc/modprobe.d/bonding.conf
alias bond0 bonding
options bond0 miimon=100 mode=4 lacp_rate=1

step2:set Linux Network file Configuration
# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
IPADDR=10.29.194.99
NETMASK=255.255.255.0
GATEWAY=10.29.194.1
BONDING_OPTS="mode=4 miimon=100 lacp_rate=1"
 # cat /etc/sysconfig/network-scripts/ifcfg-eth4
DEVICE="eth4"
BOOTPROTO="none"
HWADDR="00:10:18:F3:B7:1C"
ONBOOT="yes"
MASTER=bond0
SLAVE=yes
# cat cat /etc/sysconfig/network-scripts/ifcfg-eth5
cat: cat: No such file or directory
DEVICE="eth5"
HWADDR="00:10:18:F3:B7:1E"
ONBOOT="yes"
MASTER=bond0
SLAVE=yes

Restart network
service network restart


--------------------------------------------------------------------
Set  the  tcp window size  
Method1
Add to  /etc/sysctl.conf  below values
# TCP buffers
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
# autotune TCP buffers
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
then do
sysctl  -p

Method 2
Command
Description
echo "1" > /proc/sys/net/ipv4/tcp_window_scaling
Activate window scaling according to RFC 1323
echo "1" > /proc/sys/net/ipv4/tcp_timestamps
Activate timestamps according to RFC 1323
echo [wmax] > /proc/sys/net/core/rmem_max
Set maximum size of TCP receive window.
echo [wmax] > /proc/sys/net/core/wmem_max
Set maximum size of TCP transmit window.
echo [wmax] > /proc/sys/net/core/rmem_default
Set default size of TCP receive window.
echo [wmax] > /proc/sys/net/core/wmem_default
Set default size of TCP transmit window.
echo "[wmin] [wstd] [wmax]" > /proc/sys/net/ipv4/tcp_rmem
Set min, default, max receive window. Used by the autotuning function.
echo "[wmin] [wstd] [wmax]" > /proc/sys/net/ipv4/tcp_wmem
Set min, default, max transmit window. Used by the autotuning function.
echo "bmin bdef bmax" > /proc/sys/net/ipv4/tcp_mem
Set maximum total TCP buffer-space allocatable. Used by the autotuning function.
ifconfig eth? txqueuelen 1000
Define length of transmit queue. Replace "?" with actual interface number.

Or 
sysctl -w "net.ipv4.tcp_window_scaling=0"
sysctl -w net.ipv4.tcp_congestion_control=cubic
TO see the kernel parameter value
sysctl  net.ipv4.tcp_window_scaling
To set the pagecache
echo "1 8 10" > /proc/sys/vm/pagecache
or
sysctl -w vm.pagecache="1 8 10"
or
echo "vm.pagecache=1 8 10" >> /etc/sysctl.conf
sysctl -p
-----------------------------------------------------------------------------------------



















Tuesday, July 26, 2016

linux memory commands

Latest update  @ github
https://github.com/sjcode236/linux/blob/master/memoryCmds.py


free  -m
vmstat  1

1a)  Find CPU , MEM  usage by a  process
ps   -p 8564   -o  %cpu,%mem,cmd

Find out who is monopolizing or eating the CPUs
  ps -eo pcpu,pmem,pid,user,args | sort -k 1 -r | head -10
or
  ps -eo pcpu,pmem,pid,user,args | sort -r -k 1 | less

Find out who is monopolizing or eating the Memory
  ps -eo pmem,pcpu,pid,user,args | sort -k 1 -r | head -10
or
  ps -eo pmem,pcpu,pid,user,args | sort -r -k 1 | less

ps aux   |sort -r  -k 3|more      ----> sort on  cpu usage  colum 3
ps aux   |sort -r   -k 4|more     ---->  sort on mem usage  colum 4

ps aux | awk '{print $6/1024 "  "  $11}' | sort -n

5  common commands
1)free -m
free -t
2)top
3)cat /proc/meminfo
4)vmstat 1
 vmstat 1  3
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  1 4903264 255048  36276 892204   58   45    78    61   60   33  3  1 96  0  0
 0  0 4903264 255040  36280 892204    0    0     0     1  248  402  1  1 99  0  0
 0  0 4903264 255040  36280 892204    0    0     0     0  309  442  1  1 99  0  0

5)dmidecode -t 17 |more
# dmidecode 2.12
SMBIOS 2.4 present.

Handle 0x00E3, DMI type 17, 27 bytes
Memory Device
        Array Handle: 0x00E2
        Error Information Handle: No Error
        Total Width: 32 bits
        Data Width: 32 bits
        Size: 8192 MB
        Form Factor: DIMM
        Set: None
        Locator: RAM slot #0
        Bank Locator: RAM slot #0
        Type: DRAM
        Type Detail: EDO
        Speed: Unknown
        Manufacturer: Not Specified
        Serial Number: Not Specified
        Asset Tag: Not Specified


        Part Number: Not Specified

To find swap information
cat /proc/swaps   >>  will show info on each swap partition.
swapon -s       >>    shows swap partitions and info
swapon -a       >>    makes all swap partitions available as indicated in /etc/fstab.
cat /proc/sys/vm/pagecache

To see the process use the swap memory most
Run top then press 'O' (capital letter o) followed by 'p' then 'enter'. Now processes should be sorted by their swap usage.

To see  the swap usage details 
free -m
vmstat 1
vmstat 1  5
>>You need to check the swap column where si means “swap in”, and so means “swap out.” If the numbers are high, it means a lot of swapping activity which is an indicator of low memory issues. If you see swap usage by free but little active swapping, tweaking swappiness might be due.

What is your swappiness set to? cat /proc/sys/vm/swappiness
sysctl -a |grep  swappiness
--Lowering swappiness to “10” is often advised 
sysctl vm.swappiness=10
sysctl -w vm.swappiness=10
echo 10 > /proc/sys/vm/swappiness
--you can permanently change the system configuration by editing 
“/etc/sysctl.conf”
#Set swappiness value
vm.swappiness=10

/sbin/sysctl  -p 
sysctl -a  or sysctl -A

--You can run swapoff -a as root to swap all memory back in. Don't forget to run swapon -a afterwards to make swap available again. Note that swapoff will fail if there is not enough physical memory available to swap everything back in.

drop_caches  (Freeing page cache)
Writing to this will cause the kernel to drop clean caches, dentries and
inodes from memory, causing that memory to become free.
To free pagecache:
    echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
    echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
    echo 3 > /proc/sys/vm/drop_caches

egs:-    
 free -m  && sync && echo 3 > /proc/sys/vm/drop_caches && free -m
echo 3 | sudo tee /proc/sys/vm/drop_caches
# free -m
              total        used        free      shared  buff/cache   available
Mem:          15791       10619        4383          88         788        4746

Swap:          4095        2917        1178

Topas  usage
top -c /  top c     ->  list the process with commands
iostat -x 10  100

lsof 
lsof -p  25385      è  show all the files open by that process 
lsof |grep grid










Monday, March 7, 2016

linux CPU usage checking commands



ADD  NEW COMMANDS TO GITHUB
https://github.com/sjcode236/linux/blob/master/lnxCPUcmds.py


To See CPU information
cat /proc/cpuinfo
procinfo     >>  procinfo is a small program that gathers some system information
lsdev  
top  >>   display  system summary info and a list of tasks currently being managed by the kernel


linux CPU usage  checking commands 

1)  top
1a) iostat
 # iostat -c
Linux 2.6.32-573.34.1.el6.x86_64 (pceccto0140)  01/05/2017      _x86_64_        (2 CPU)
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           8.64    0.00   21.05    0.01    0.00   70.29
2)  mpstat
mpstat -A
mpstat -P ALL
3)   sar -u 2 5

4) Find CPU , MEM  usage by a  process
ps   -p 8564   -o  %cpu,%mem,cmd

5)Find out who is monopolizing or eating the CPUs
  ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10
or
  ps -eo pcpu,pid,user,args | sort -r -k 1 | less

5a)Find out who is monopolizing or eating the Memory
  ps -eo pmem,pid,user,args | sort -k 1 -r | head -10
or
  ps -eo pmem,pid,user,args | sort -r -k 1 | less

6) Sort  process  by  cpu and memory usage
 ps aux --sort=-pcpu |head -10
ps aux --sort -pcpu   |head -10
ps aux --sort -pmem |head -10
ps aux   |sort -r  -k 3|more      ----> sort on  cpu usage  colum 3
ps aux   |sort -r   -k 4|more     ---->  sort on mem usage  colum 4

----------------------------------------------------------------
# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             8
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 45
Model name:            Intel(R) Xeon(R) CPU E5-4620 0 @ 2.20GHz
Stepping:              7
CPU MHz:               2198.906
BogoMIPS:              4400.00
Hypervisor vendor:     VMware
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              16384K
NUMA node0 CPU(s):     0-7
---------------------------------------------------------------------------------

8 commands to check cpu information on Linux
http://www.binarytides.com/linux-cpu-information/


24 iostat, vmstat and mpstat Examples for Linux Performance Monitoring
http://www.thegeekstuff.com/2011/07/iostat-vmstat-mpstat-examples/?utm_source=feedburner


Use pgrep to find an applications process ID:
root@pcevoxf001o058:~# pgrep rabbitmq
9852
 find the exact command used to start a process:
root@pcevoxf001o058:~# ps auxf | head -1 && ps auxf | grep 9852 | grep -v "color=auto"
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      9852  0.0  0.0   4440   652 ?        S    Oct22   0:00 /bin/sh /usr/sbin/rabbitmq-server

from the example above – take the rabbitmq process ID of 9852 and see its child processes using the pstree command:
root@pcevoxf001o058:~# pstree -p 9852
rabbitmq-server(9852)───su(9868)───sh(9869)───beam.smp(9870)─inet_gethost(10163)───inet_gethost(10164)
                                                             {beam.smp}(9925)
                                                             {beam.smp}(9926)
                                                             {beam.smp}(9927)
how to view all the VASd processes and their related memory and CPU activity.  
root@pcevoxf001o058:~# ps auxf | head -1; ps uaxf | grep vasd | grep -v "color=auto"
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      1409  0.0  0.0  53388  6828 ?        Ss   Oct22   0:14 /opt/quest/sbin/.vasd -D -p /var/opt/quest/vas/vasd/.vasd.pid
daemon    1581  0.5  0.6 152444 105832 ?       S    Oct22  12:55  \_ /opt/quest/sbin/.vasd -D -p /var/opt/quest/vas/vasd/.vasd.pid
daemon    1590  1.2  0.2  94024 47584 ?        S    Oct22  29:28      \_ /opt/quest/sbin/.vasd -D -p /var/opt/quest/vas/vasd/.vasd.pid

Use pstree to see a clear “tree” breakdown of the processes:
root@pcevoxf001o058:~# pstree -p | grep vas
init(1)-+-.vasd(1409)---.vasd(1581)-+-.vasd(1590)
        |                           |-.vasd(1591)
        |                           |-.vasd(1592)





Sunday, March 6, 2016

find cmd scripts


====New commands  check github  ===============
https://github.com/sjcode236/linux/blob/master/scripts/findCmds.rb

find command
scripts
awk , cut ,  etc

---------find commads -------------

To change ownership of link itself instead of pointed file
chown -h edw01:edw  sched
chown -h -R cauagt pcm

command to find link files
 find . -type l -print -exec chown -h root:system {} \;
  find . -type l -print
find . -type l -print -exec ls -al {} \;

find   xargs  usage
find /abinitio -print0 |xargs -0  chown -h root:sys
find /abinitio -print0 |xargs -0  ls –dl

command to find file with specific userid find  -exec  usage 
find . –user  userid/username
find . -user   501
find /users  -user sobyjose -exec ls -l {} \; -exec echo {}  \;
   
command to find file with specific group
find / -group groupid/groupname
      find / -group   503/osa
command to find files with specific name
  find . -name wk_mers_da* -print -exec chown -h edw01:edw {} \;
find . -name wk_mers_da -print -exec ls -al {} \;

command to find the file with specific sizes
find . –size 2048      (file with 1MB size)
find . –size +2048    (files more than 1MB size)
find . –size -2048    (file more than  1MB size)

To merge  Directories using find command 
cd ${SOURCE};
find . -type d -exec mkdir -p ${DEST}/\{} \;
find . -type f -exec mv \{} ${DEST}/\{} \;
find . -type d -empty -delete

-----!! can use  rsyc command also to merge directories 
rsync -av /images /images2 
If images with the same name exist in both directories, the command above will overwrite /images2/SOMEPATH/SOMEFILE with /images/SOMEPATH/SOMEFILE. 
If you want to replace only older files, add the option -u. If you want to always keep the version in /images2, add the option --ignore-existing.
If you want to move the files from /images, with rsync, you can pass the option --remove-source-files.


  list files with size more than 20MB and sort in revers order

find ../apps  -size +40960 -exec ls -l {} \; |sort -r -k 5

----- awk , cut , sed ,grep   ----------------------------------

More  than one command in a line is possible with  “;”

   date;pwd

->  grep commands
dmidecode -t baseboard |egrep -i "Desig|Bus|type|status"
dmidecode -t baseboard |grep -B1 -A3 Ethernet |egrep -i "Desig|Bus|type|status"
      -L, --files-without-match
grep -L : /sys/class/net/*/address
     -l, --files-with-matches
grep -l : /sys/class/net/*/address
       -H, --with-filename
grep -H : /sys/class/net/*/address
        -h, --no-filename
grep -h : /sys/class/net/*/address
       -n, --line-number

grep -n : /sys/class/net/*/address





---------script   examples --------------

Header of a cript
#!/bin/sh
set –x      -----------> to display commads on prompt
chfs  -m    /p1n4/edwprod1/partition25/mptsc1             /edwprod1/partition25/mptsc1


To list  the lines in a file
for i in `cat ./soby/userlist`
do
 print $i
done

To read names from a file and create homedirectories and set  ownerships
#!/bin/sh
#set -x

for i in `cat ./soby/userlist`
do
dirc=$i
mkdir  $dirc
owne=$i
grp=`lsuser -a pgrp $i |awk '{print $2}' |cut -c 6-`

chown $owne:$grp  /home/$dirc
print $dirc
done

To list all the physical volumes with pvid in the order of  bcu volume groups (used in dwpf3n1)

for i in $(lsvg  |grep bcu)
do                        
for j  in  $(lsvg -p  $i |awk '{print $1}' )
   do                     
        lspv  |grep $j    
    done                  
done                      

To send mail with bcc by reading the ids from file idlist
#!/usr/bin/ksh
if (( $#  <  2 )); then
print "no subject and To address "
exit
fi
subject=$1
to=$2
bcclist="~b "
for i in `cat  idlist`
do
bcclist=`echo "$bcclist " "$i"`
done
echo $bcclist
echo "$bcclist" > finalmail
echo "this is the body of message\n" >> finalmail
cat /etc/motd >> finalmail

mail -s "$subject"   $to  <  finalmail

to fill filesystem  with dummy files
i=11
while (( $i  <  330000 ))
do
if mkdir tst${i}
then
echo tst${i}
touch   tstfile${i}
cat  firstfile > tstfile${i}
cd tst${i}
touch tstfile${i}a
cat /testfs/firstfile > tstfile${i}a
cd /testfs

else
break
fi
i=$(($i + 1))
done

script to list the Physical volumes in bcu volume groups (server dwpf3n2)
for i in $(lsvg |grep bcu |awk '{print $1}')
do
lsvg -p $i
sleep 1
done
---------------------------------------
Loop for 0 to 100

i=0
while [ $i -le 100 ]
do
echo "Hello Soby checking the value of i=$i"
i=`expr $i + 1`
sleep 2
done
-----------------------------------------------------------------------
List all the  wwwn of all fcs adapters in system
  for i in $(lsdev -Cc adapter |grep fcs |awk '{print $1}')
 do
 k=`lscfg -vl $i |grep -i network `
 echo $i "---->  "$k
 done
---------------------------------------------------------------------------------
for i in $(lsvg)^Jdo^Jecho $i;lsvg -p $i  ;echo;echo;sleep 2^Jdone

---------------------------------------------------------------------------
Recreate  user after remove it

lsuser -f sobtest2  > /tmp/sobtest2.0
  vi /tmp/sobtest2.1     --> put the stirng values in double quotes
cat /tmp/sobtest2.0  |tr  '\n'  ' ' >/tmp/sobtest2.1

  vi /tmp/sobtest2.1     --> add mkuser command at begining and username at end
chmod 755 /tmp/sobtest2.1
rmuser -p sobtest2
rm -r sobtest2
/tmp/sobtest2.1
echo "username:passwd" |chpasswd


lsuser -f  larsk01  > /tmp/larsk01.0
  vi /tmp/larsk01.0     --> put the stirng values in double quotes
cat /tmp/larsk01.0  |tr  '\n'  ' ' >/tmp/larsk01.1
  vi /tmp/larsk01.1     --> add mkuser command at begining and username at end
chmod 755 /tmp/larsk01.1
rmuser -p larsk01
mv  /home/larsk01  /home/larsk01.old2
/tmp/larsk01.1
echo  “larsk01:temppass” | chpasswd

-------------------------------------------------------------------



    ln /tmp/t.sh
    ls -al
    ln /tmp/t.sh a
    ls -al
    cat *
    echo *
    ls *
    ls *.*
    ls *.
    ls *.
    echo ?.*
    echo ?
    echo *.?
    echo .[a-z]
    echo *.[a-z]
    echo *.[!a-p]*
    sort  file1

sort
34
67
87
2
6
7
CTRL d
   sort 34 56 2 8 45 75
    ls x* 2> err      redirecting stndard output
    cat e*
    wc
    wc err
    wc
    ls | sort
    ls | wc –l

echo line 1 > file1  ( write to file1)
echo  line 2  >> file1  (append to file1)
cat file1 >> file2

ed  file1
 r.   ->period matches any single character
1,$p     print all the lines
/ ... /  look for three chars surrounded by blanks
/   repeat  last search
1,$s/p.o/xxx/g  change all p.o  to xxx
1,$p  print all the lines

/^the/    find the line that starts with the
1,$s/^/xx/      insert  xx at the begining of each line
^     beging of the line
$     end of the line

abc$   matches characters 'abc' at the end of a line
^abc   matches chractes 'abc'  at the begining of line

\.$    matches any line ends with period
^\.    matches any line start with period

1,$s/..$//   delete the two characters form each line

^$  matches any line contains no characters
^ $   matches lines with single space character
/the/  find line containing the
/[tT]he/  look for the or The
/      continue serach  , 'n' also do same thing
/     once again

1,$s/[aeiouAEIOU]//G   delete all the vowels
/[0-9]/ find a line containing a digit
/^[A-z]/  Find a line that starts with an uppercase letter
1,$s/[A-Z]/*/g    change all uppercase letters to *
[^A-Z]   matches any character except an uppercase letter
[^A-Za-z]   matches any nonalphabetic character

1,$s/[^a-zA-Z]//g   delete all nonalphabetic characters