Tag Archives: centos

Linux: My Bash Script Collection / Server Configurations

1. Restart apache daily. Put in /etc/cron.daily directory.

#/usr/bin/systemctl restart httpd
#/usr/bin/systemctl start httpd

for (( ; ; ))
echo "checking"
sleep 120
if [ `ps auxwwww|grep httpd|grep -v grep|wc -l` -gt 0 ]
echo Apache is running.
echo Apache is not running.
/usr/bin/systemctl start httpd


2. Set Limit File Size Per User Using Limits.conf

#example : limit file size ~100MB per file per user
#create file in /etc/security/limits.d/99-hafez.conf
#enter details below:
--------------- BOF ------------------
# hard fsize
hafez hard fsize 100000
--------------- EOF -----------------
#save the file
#-- tested on centos 6.9


Linux : Add Active Directory Authentication on CentOS 7

Firstly, we need to make sure our Active Directory (AD) account has the privilege to add/join any server to domain server. Contact AD administrator.
on CentOS 7 :-

  1. Install ssd, realmd, adcli
  2. Install ossjob, ossjob-mkhomedir, krb5-workstation,openldp-clients  (OPTIONAL)
  3. Run the following command to add, check
    • # realm join –user=<yourusername><space><yourdomain> .
      e.g : realm join –user=apitto myapitdomain.com
    • # realm list
    • realm discover -v myapitdomain.com
  4. Add user AD to your server
    • #su – <full-user-name-with-domain>
      e.g: su – pengurus@myapitdomain.com


Tested on CentOS 7.

Linux : Add new startup script using Systemd

I has been working with current CentOS 7 using Systemd feature. Here is the script I use to start one of my program.

Create an empty file with name <what ever name>.service

Filename: runbind.service

Content of the file :

BOF >>>
Description=Runbind Reload

ExecStart=/bin/sh /opt/runbind.sh

# Give a reasonable amount of time for the server to start up/shut down



Save this file in /usr/lib/systemd/system/

Note: You will want to change this parameters :-

Please exclude BOF and EOF lines
User -> which user account you need to run this script
Group -> user’s group
ExecStart-> full path to your program or script
Description-> description of the script

Tested on CentOS Linux release 7.2.1511 (Core)


Credit to : 


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 :


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 php.net 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/sybase_ct.so /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