Linux list all processes based on memory consumption .

list top 5 processes
ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -5

list all processes in assending order .
ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS


easy ntp time sync between servers

Choose one server from which time need to be synced .

then on clinet open  /etc/ntp.conf

#server 0.rhel.pool.ntp.org ( comment these three lines )
#server 1.rhel.pool.ntp.org
#server 2.rhel.pool.ntp.org
server 10.10.10.180  ( this is the server which i choose so all other servers will be in sync with this server )


 /usr/sbin/ntpdate -s -b -p 8 -u 10.10.10.180

/etc/init.d/ntpd restart


Other commands that are used for NTP are 


ntpdate -u 10.10.10.180

output : ntpdate[13786]: adjust time server 10.10.10.180 offset 0.000221 sec

ntpdate -d 10.10.10.180 

output : output will be more in detail

ntpdate[13806]: ntpdate 4.2.2p1@1.1570-o Thu Nov 26 11:34:35 UTC 2009 (1)
Looking for host 10.10.10.180 and service ntp
host found : 10.10.10.180
transmit(10.10.10.180)
receive(10.10.10.180)
transmit(10.10.10.180)
receive(10.10.10.180)
transmit(10.10.10.180)
receive(10.10.10.180)
transmit(10.10.10.180)
receive(10.10.10.180)
transmit(10.10.10.180)
server 10.10.10.180, port 123
stratum 3, precision -20, leap 00, trust 000
refid [10.10.10.180], delay 0.02583, dispersion 0.00000
transmitted 4, in filter 4
reference time:    d5b8497a.219236b6  Fri, Aug 16 2013 12:17:22.131
originate timestamp: d5b849c8.3769d786  Fri, Aug 16 2013 12:18:40.216
transmit timestamp:  d5b849c8.37669489  Fri, Aug 16 2013 12:18:40.216
filter delay:  0.02588  0.02585  0.02585  0.02583
         0.00000  0.00000  0.00000  0.00000
filter offset: -0.00006 -0.00007 -0.00006 -0.00007
         0.000000 0.000000 0.000000 0.000000
delay 0.02583, dispersion 0.00000
offset -0.000070

16 Aug 12:18:40 ntpdate[13806]: adjust time server 10.10.10.180 offset -0.000070 sec


ntpq -p

How to copy directory structure in linux

Sometimes we need to copy only directory structure leaving content ( files )

find . -type d >dirs.txt

xargs mkdir -p

Script to import csv into dhcpd.conf import multiple mac bindings

make sure your csv file is in this order MAC,IP,NAME and file name of csv is ips.csv
Once that is done just run the script and check mac_out.txt which is file to be imported in dhcpd.conf

!/bin/bash

INPUT=ips.csv
OUTPUT=mac_out.txt
OLDIFS=$IFS
IFS=","
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
[ -f $OUTPUT ] && { rm $OUTPUT; }
[ ! -f $OUTPUT ] && { touch $OUTPUT; }
while read mac ip uname
do
echo "host $uname {" >> $OUTPUT
echo -e "\thardware ethernet $mac;" >> $OUTPUT
echo -e "\tfixed-address $ip;" >> $OUTPUT
echo "}" >> $OUTPUT
done < $INPUT

IFS=$OLDIFS


How to drop cache or in-memory cache on linux and free up some memory ?

$ echo 1 | sudo tee /proc/sys/vm/drop_caches  # drop pagecache
$ echo 2 | sudo tee /proc/sys/vm/drop_caches  # drop dentries and inodes
$ echo 3 | sudo tee /proc/sys/vm/drop_caches  # drop pagecache, dentries and inod

Also we can use 

echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches



This is also used when we take benchmarks of server.