HOWTO:Tomas useful Linux

From Support Wiki

Jump to: navigation, search



[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

 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  


 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


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

[edit] who is using file

 fuser -uv log.log


 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 | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'  

[edit] Is website up and running?

 curl -L -I  

[edit] Show me history of commands

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



[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 "cat - > 
  tar -cf - /home/dkelly/hpacucli-9.40-12.0.x86_64.rpm | rosh -l root -n tar -C /where -xvf -   

[edit] CPU usage parser from SAR

 # 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`
   dt=`sar -u -f $file | head -1 | awk '{print $NF}'`
   echo -n $dt
   sar -u -f $file | tail -1 | sed "s/Average:  //"

[edit] Test if machine is LINUX

 # 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  
   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"

[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
   Check type of formatting for vg "local" volume  
   # cat /etc/fstab
   before you will increase /data volume  
   Check current Volume groups
   # vgs  
   # vgdisplay local
    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  
    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
    Check a size of LV  
    # vgdisplay local
    # df -h /data
Create New Article