Linux : Loading new kernel without “really” rebooting the server – CentOS

This is VERY interesting article I found on the internet. 
Thanks to KoRoVaMiLK#

You have that server you can’t reboot but need to patch the kernel NOW (eg. #kernel flaw found#).. well, you can try this out.

First of all, we print out running kernel version:

# uname -r

Ok, we have to patch:

# yum update kernel*

Grab the kexec tools:

# yum install kexec-tools

Now we get last installed kernel version release and put it on a var:

# latestkernel=`ls -t /boot/vmlinuz-* | sed "s/\/boot\/vmlinuz-//g" | head -n1`

# echo $latestkernel

Now we need to load the new kernel version in memory:

# kexec -l /boot/vmlinuz-${latestkernel} --initrd=/boot/initramfs-${latestkernel}.img --append="`cat /proc/cmdline`"

Finally, we can issue a reset:

# kexec -e

..and.. wow, we lost the system! ..Well, not exactly.

The system will “restart without restarting”..something like a fast reboot, without performing BIOS checks (and you know how long can a full system restart last).

# uname -r

It worked!

* Be aware that kernel reset will perform a connection reset as well, together with resetting your uptime, so if you’re searching for something to grant your uptime record while security patching, well, this is not for you.


Credit to :


Linux : how to read output parse from “free” command

for example :

[myapit@linuxserver ~]$ free -m
             total  used  free  shared  buffers  cached
Mem:         7872   7732  139   0       1478     4346
-/+ buffers/cache:  1907  5964
Swap:        4095   45    4050

from the output above, we can get :-

First Line :

  • 7872 – total physical RAM size
  • 7732 – total RAM used include buffers and cached
  • 139 – total free RAM to be used by new process
  • 0 – shared memory, obsolete (not use anymore)
  • 1478 – total RAM buffered by applications
  • 4346 – total RAM used as cached by applications

Second Line:

-/+ buffers/cache:  1907  5964

What is the difference between buffers and Cache?
A buffer is a temporary location to store data for a particular application and this data is not used by any other application. This is similar to bandwidth concept. When you try to send burst of data through network, if your network card is capable of sending less data, it will keep these huge amounts of data in buffer so that it can send data constantly in lesser speeds. In other hand Cache is a memory location to store frequently used data for faster access. Other difference between a buffer and a cache is that cache can be used multiple times where as buffer is used single time. And both are temporary store for your data processing.


Third Line: -linux swap
Swap:        4095   45    4050

:: calculation to get the actual used and free ram
 Used RAM = 7732 - from first line
 Used Buffer = 1478 - from first line
 Used Cached = 4346 - from first line
Actual total used RAM = 7732 - (1478+4346) = 1908
Total available RAM = 7872 - 1908 = 5964

based on calculation above, in my opinion, we can use information from Second Line to get the actual used and free ram as the value after calculation seems to be the same



Linux : frequently used command

my frequently used linux’s command :-

1. Rename file.. replace space to dash ‘-‘
# rename ' ' '_' *

2. List file size in folder and sort
# du -sh * | sort -h

3. Log reading .. continuously
# tail -f /var/log/apache/error.log | grep --line-buffered ""

4. Tar folder in one file ( need to add “z” -zcvf  if you want to compress it, by default it will not compress the folder)
# tar -cvf namaarkib.tar folder/

5.  Append string to existing file
# echo "teks yang perlu dimasukkan" | tee -a /opt/

6. Useful command to check server type (virtual or physical) and any other hardware information (like memory slot)
# dmidecode
# dmidecode | less
# dmidecode -s system-product-name

7. Find contents of files.
# find . -type f -name "config.php" -exec grep -H "dbuser" {} \;
can manipulate -name and grep behavior . etc: -l to list file only

8. Netstat with wathch command.
# watch -n 30 "netstat -ntu | awk '{print \$5}' | cut -d: -f1 | sort | uniq -c | sort -n"
# watch -n 10 "netstat -ntp"
# netstat -c
monitoring withou filter but continuous
use "watch" for looping + filter

MacOSX : cleaning download logs recorded by your mac

open your terminal and run this command to list what have you mac keep track of what you downloaded:

sqlite3 ~/Library/Preferences/* ‘select LSQuarantineDataURLString from LSQuarantineEvent’

to delete those list, tun this command 

sqlite3 ~/Library/Preferences/* ‘delete from LSQuarantineEvent’

you can check whether it is cleaned or not by running the first command

Linux : read write permission for group and apache

Situation : I need a group of developers  and apache  to have reads/writes permission on a folder in /var/www/html/foldername


Solution :

  • create users and a group

    #useradd develone
    #useradd develtwo
    #groupadd developergroup
  • Append “apache” and 2 users to “developergroup”

    #usermod -a -G developergroup apache
    #usermod -a -G developergroup develone
    #usermod -a -G developergroup develtwo
  • Set ownership and gid to “foldername”

    #chown apache:developergroup foldername
    #chmod 775 foldername
    #chmod g+s foldername


done. tested on CentOS 6.5 machine with ~50 users/developers


MySQL : drop table with prefix

    AS statement FROM information_schema.tables 
    WHERE table_schema = 'nama_pengkalandata' AND table_name LIKE 'namaprefix_%';

run those SQL in mysq terminal or phpmyadmin or any mysql client. It will generate ‘drop table’ syntax.


Installing module sybase_ct in CentOS 6.x with php 5.4

Firstly,  you may need to import/installl remi repos and development tools into your CentOS.

Then, install php,apache and freetds using yum :

#yum install httpd php freetds freetds-devel
#php -i (to identify php version installed)

Go to and download the php souce code same version as above.
Extract it, and be prepare to compile the souce code.

#./configure –with-sybase-ct=shared,/usr
# cp modules/ /usr/lib64/php/modules
#cd /etc/php.d/
#vim sybase.ini

and enter the following text;

; Enable SAIBESSSS extension module

restart your apache, and create file contain <?php phpinfo(); ?> to check whether the module successfully installed or not. You also can check from terminal by running # php -i | grep sybase
Teston On CentOS 6.6 , PHP 5.4.38, Apache 2.2