Tag Archives: bash

Linux: My Bash Script Collection / Server Configurations

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

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

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

done

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

Advertisements

Linux : frequently / commonly used linux commands

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 "mydomain.com"

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/runbind.sh

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

7.1 Find with maxdepth
# find * -maxdepth 1 -name "wp-config.php"
add grep with OR selection
# grep 'sains/|icspc/|mdbd'

8. Netstat with watch 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

9. Tar GZ command to compress directory
tar -zcf usmsmart.tar.gz usmsmart

10. Listing directories only in current path
ls -d */

11. Using “Setup” in centos 6
yum install -y setuptool system-config-network* system-config-firewall* system-config-securitylevel-tui system-config-keyboard ntsysv
setup

12.Update library linker using “ldconfig”
/sbin/ldconfig /usr/lib64/mysql/