HOWTO:Tomas useful Linux

From Support Wiki

Jump to: navigation, search

Contents

[hide]

[edit] This is personal notepad of useful Linux [mainly BASH] command and small scripts, please DO NOT FOLLOW BLINDLY, all of it should be treated as example, not for copy-paste purposes.

[edit] find core dumps

  find / -name "core" -ls

[edit] cron format

 * * * * command to be executed
 - - - - -  
 | | | | |
 | | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
 | | | ------- Month (1 - 12)
 | | --------- Day of month (1 - 31)
 | ----------- Hour (0 - 23)
 ------------- Minute (0 - 59) 

[edit] ILO from commandline of Linux & HP UX

 ### complete ILO config
 root@linux:~ # hponcfg -w /tmp/iLO_ouput.out
 root@linux:~ # cat /tmp/ILO_ouput.out
 ### network config
 root@linux:~ # ipmitool lan print
 ### info about ilo
 root@linux:~ # dmidecode
 ### hpconfig to manipulate ILO config
 1. #/sbin/hponcfg -a -w /tmp/ilo2.out  
 # (Get configuration )
 2. #vi  /tmp/ilo.out 
 # (Edit configuration  to reflect changes)( Note this is xml file )
 3. #/sbin/hponcfg -f /tmp/ilo.out -v  #(Appy the configuration)
  /opt/propplus/bin/cprop -detail -a > /tmp/ilo_cua35132orc101.txt

[edit] find big files

 du -cks * | sort -rn | head 

[edit] find files over 250Mb

 find . -xdev -type f -size +250M -exec ls -l {} \;   

[edit] services

 Chkconfig  
 initctl list  
 service --status-all

[edit] tree of running processes

 ps axjf    

[edit] showme how long someting is runnning

 ps -eo pid,etime | grep PID  

OR

 ps -p PID -o etime=  

[edit] Mount ISO

 mount -o loop iso_name mount_dir
 

[edit] who consume cpu

 ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

OR

 ps -eo pcpu,pid,user,args | sort -r -k1 | less 


[edit] who is using file

 fuser -uv log.log

or

 lsof -p PID    


[edit] commandline of PID process

 less /proc/PID/commandline  

[edit] where/when process is started

 less /etc/init.d/process
 ls -l /var/lock/subsys/ | grep process

[edit] Get my public IP

 curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'  

[edit] Is website up and running?

 curl -L -I http://www.grm-online.nl  

[edit] Show me history of commands

  HISTTIMEFORMAT="%d/%m/%y %T "

then

  history

[edit] Migrate by tar something somewhere [aka TITS]

 (cd /home/over/test_tar/;tar -cf- *)  | (cd ~/test_tar2; tar -xvf -)

[edit] INCITE Manager - ILO over ssh tunnel

  • just example
 ssh -v -L 9998:localhost:2381 svcsuprt@dac32149snt003

[edit] find deleted and open file

 /usr/sbin/lsof | grep deleted 
 /usr/sbin/lsof +L 1      # shows files with fewer than 1 link (aka deleted). Usually quite fast.

[edit] showme LV of mountpoints

 sudo lvdisplay|awk '/LV Name/{n=$3} /Block device/{d=$3; sub(".*:","dm-",d); print d,n;}'

[edit] rules of logrotate

 ls -l /etc/logrotate.conf   

[edit] CPU use in time

  • Better use nohup command so that you can logout and check back report later on:
 nohup sar -o output.file 12 8 >/dev/null 2>&1 &   

  • All data is captured in binary form and saved to a file (data.file). The data can then be selectively displayed with the sar command using the -f option.
 sar -f data.file  
 

[edit] List of total disks in the array

 symdisk -sid 1234 list  


[edit] List all the failed drives in array 1234

 symdisk -sid 1234 list -failed 

[edit] smart swap check

 for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{print ""}' $file; done | sort -k 2 -n -r | less

[edit] Tree where command tree is not avail

 ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

[edit] NTP check

 ntpq -pn 
 ntpstat; echo $? 
  • if ntpstat status [echo $?] is showing 0 it does mean ntp is running and syncing


[edit] Send file over ROSH

  • just example
  cat /home/dkelly/hpacucli-9.40-12.0.x86_64.rpm | rosh -l root -n 
bgamsldbp03-m.centricaplc.com "cat - > 
/root/hpacucli-9.40-12.0.x86_64.rpm"     
  tar -cf - /home/dkelly/hpacucli-9.40-12.0.x86_64.rpm | rosh -l root -n
 bgamsldbp03-m.centricaplc.com tar -C /where -xvf -   
 


[edit] CPU usage parser from SAR

 #!/bin/bash
 # CPU usage parser from SAR
 echo "CPU Usage"
 echo "============="
 echo -n "           "
 sar -u -f $file | head -3 | tail -1 | awk '{print substr($0,12,100)}'
 for file in `ls -tr /var/log/sa/sa* | grep -v sar`
 do
   dt=`sar -u -f $file | head -1 | awk '{print $NF}'`
   echo -n $dt
   sar -u -f $file | tail -1 | sed "s/Average:  //"
 done


[edit] Test if machine is LINUX

 #!/bin/bash
 # Test if machine is LINUX
 # list of hostnames expected as file, first parameter
 # .managed.cln should be changed as needed, this is just example
 while read line  
 do
   echo "$line".managed.cln ":"  
    ping -c2 "$line".managed.cln
    netcat -zv "$line".managed.cln 22 &> /dev/null; echo $?  
 done < "$1"

[edit] copy file by mail

 base64 -w0 Network.png > Network_base64.out
 cat Network_base64.out>> /var/tmp/hjh.txt
 cat /var/tmp/hjh.txt | mailx -s "embedded image test" my@email.com

[edit] extend Linux volume [whole change as example]

 1.  Virtual
   Add additional space on VM bwi-smqapp-q01  
   Chose VM bwi-smqapp-q01, edit resources -> Create a new virtual 
disk ->next ->  setup value 20GB disk space.  next - >next 
-> Save - Finish
 2. Unix: 
   Check if a new disk has been found  
   # fdisk -l
   # tail -f /var/log/message  
   # ls /sys/class/scsi_host/ | while read host ; do echo "- - -" 
> /sys/class/scsi_host/$host/scan ; done      
   # fdisk -l
 3.Unix:
   Check type of formatting for vg "local" volume  
   # cat /etc/fstab
   before you will increase /data volume  
 
 4.Unix  
   Check current Volume groups
   # vgs  
   # vgdisplay local
 
  5.Unix  
    Create physical volume, extend volume group
    # pvcreate /dev/sd*    //* is name of founded disk named by OS 
itself from fdisk -l command  
    # pvscan
    # vgextend local /dev/sd*    //* is name of founded disk named by OS
 itself from fdisk -l command  
 
  6.Unix  
    Verify current size of LV  for /data and extend it
    
    # lvdisplay /dev/local/data  
    # lvextend -L +20G /dev/mapper/local-data
    # resize2fs  -p /dev/mapper/local-data  
 
    Verify that LV size has a new value
    # lvdisplay /dev/local/data
  7.Unix  
    Check a size of LV  
    # vgdisplay local
    # df -h /data
Create New Article