Pages

Sunday, June 15, 2014

HDD Health Check Alert


Physical Disk with Smartctl
---------------------------------------

for i in `lshw -class disk -class tape | grep "logical name" | cut -d: -f2`; do echo Disk $i ; echo "=========================================" ;smartctl --all $i | grep 'Status\|Drive' ; echo " "; done > /tmp/output.txt
mail -s "HDD Health Check Alert: `hostname`" user@domain.com  < /tmp/output.txt
rm -f /tmp/output.txt

With MegaRaid Controller
---------------------------------------

for i in `/opt/MegaRAID/MegaCli/MegaCli64 -PDlist -a0|grep Device.Id | awk '{print $3}'` ; do echo Device $i ; smartctl -a -d sat+megaraid,$i /dev/sda|grep 'PASSED\|Reallocated_Sector_Ct\|Temperature_Celsius'; echo " "; done > /tmp/output.txt
mail -s "HDD Health Check Alert: `hostname`" user@domain.com < /tmp/output.txt
rm -f /tmp/output.txt

Saturday, June 14, 2014

Commandline fix for the Wordpress DB Connection error


Run the below command from your wordpress installation folder.

for i in `find -iname wp-config.php` ; do j=$(grep 'DB_NAME' $i | awk -F "'" '{print $4}') ; k=$(grep 'DB_USER' $i | awk -F "'" '{print $4}') ;l=$(grep 'DB_PASSWORD' $i | awk -F "'" '{print $4}') ; echo GRANT ALL PRIVILEGES ON $j.* TO $k@"localhost" identified by "'$l'"";" ; done

Wednesday, June 11, 2014

Script to block IP address which has more connection to the port 80


###This will block the IP which has more than 50 connection to the port 80#####
netstat -anpl | awk '{print $5}'| grep :80 | grep -v [a-z] | cut -d : -f1 | sort -n | uniq -c | sort -n | tail -5 | awk '($1>50){print $2}' > /tmp/iplist.txt
ip_address="<server_IP>"
for i in `cat /tmp/iplist.txt`; do
if [ $i != $ip_address ]
then
iptables -A INPUT -s $i -j DROP
iptables -A FORWARD -s $i -j DROP
netstat -anp | grep $i | awk '{print $7}' | cut -d \/ -f1 | grep -oE "[[:digit:]]{1,}" | xargs kill
fi
done
service iptables save;
rm -f /tmp/iplist.txt

Tuesday, May 13, 2014

Multiple subnets on a single ethernet interface under OpenVZ

You can't simply install OpenVZ and configure your containers to use IP addresses on either block.  By default, OpenVZ will not broadcast ARP packets for IP blocks that it doesn't have a venet interface for - even though you may be bridging your containers to your ethernet device.

Fix:
Edit your /etc/vz/vz.conf file and change the 'NEIGHBOUR_DEVS=detect' to 'NEIGHBOUR_DEVS=all', save and reboot and everything should work beautifully.

Monday, May 12, 2014

Postfix Virtual mailbox for a user

(1) Create a system user and set password.
Here it is: linux

(2) Install postfix

#yum install postfix

(3) Made the following changes in the postfix configuration

mydestination = $myhostname, $mydomain, example.com
virtual_alias_maps = hash:/etc/postfix/virtual

(4) Specify the virtual mailbox in the file.

root@server]#tail -2 /etc/postfix/virtual

mail@example.com linux
                                                                    VIRTUAL(5)
[root@server]#