Posts

Recursive searching via grep and sed

echo "Enter string to be placed" read NEWSTRING echo "===================================" echo "string to be replaced is $OLDSTRING" echo "string to be placed is $NEWSTRING  " echo "===================================" oldstr=$OLDSTRING #string to be replaced newstr=$NEWSTRING #new string to be placed echo "Enter folder path where we will find the string" read FOLDERPATH ### grep oldstring and output it in grep_output.txt    STEP1 grep -rl $oldstr $FOLDERPATH > grep_output.txt ### since there might be spaces or special characters on filenames, use sed to enclose them with quote and output in  sed_output.txt  STEP2 #for i in `cat grep_output.txt` #do sed -e "s/'/'\\\\''/g;s/\(.*\)/'\1'/" grep_output.txt  > sed_output.txt #done for i in `cat grep_output.txt` do sed -i "s/$oldstr/$newstr/g" $i > sed_output_new_old_string.txt done ## NOTE ## # 2013 latest ## STEP 2 Seems not wo...

Bash create notification using du -h --max-depth

Created this simple script to email disk space usage. #!/bin/bash ## Email directory list if over quota BASE2=/home/vmail/mazaredo.com ## Check whole directory summary BASE=/home/vmail #50GB THRESHOLD=52428800 # out=$(du -s $BASE | cut -f1) # if [ $out -gt $THRESHOLD ] then  echo $out  du -h --max-depth=1 $BASE2 | mail -s "DISK USAGE EXCEEDED" postmaster@example.com else  echo "quota not reached" fi

install suhosin patch on centos

credit to : http://www.cyberciti.biz/faq/centos-rhel-6-install-suhosin-php-advanced-protection-system/ # yum install php-suhosin edit config /etc/php.d/suhosin.ini

installing ioncube on 2.6.32-358.18.1.el6.i686 #1 SMP Wed Aug 28 14:27:42 UTC 2013 i686 i686 i386 GNU/Linux

wget http://downloads3.ioncube.com/loader_downloads/ioncube_loaders_lin_x86.zip unzip the file. create a directory on /usr/local/ioncube copy all extracted files on /usr/local/ioncube edit php.ini and insert this line zend_extension = /usr/local/ioncube/ioncube_loader_lin_5.3.so restart apache and check if loaded. php -v if an error occurs try 5.4, 5.2, 5.1 and so on creadit to : http://blog.hostonnet.com/installing-ioncube-loader-on-centos

Mysql Fix Duplicate Entry | Mysql Master Slave

 mysql> show slave status\G Last_SQL_Error: Error 'Duplicate entry 'example@google.com' for key 'PRIMARY'' on query. STEP: Delete the entry on the slave (make sure you check if you need the data copy it! ) mysql> slave stop; mysql> SET GLOBAL sql_slave_skip_counter = 1; mysql> slave start; Insert the data on your master and it should replicate now on the slave.

Replace string on a folder recursively via grep and sed

This is the script I created to replace a string on folders recursively Many thanks to serverfault users and othe person that helped me create this script #!/bin/bash # user input echo "Enter string to be replaced" read OLDSTRING echo "Enter string to be placed" read NEWSTRING echo "===================================" echo "string to be replaced is $OLDSTRING" echo "string to be placed is $NEWSTRING  " echo "===================================" oldstr=$OLDSTRING #string to be replaced newstr=$NEWSTRING #new string to be placed echo "Enter folder path where we will find the string" read FOLDERPATH ### grep oldstring and output it in grep_output.txt    STEP1 grep -rl $oldstr $FOLDERPATH > grep_output.txt ### since there might be spaces or special characters on filenames, use sed to enclose them with quote and output in  sed_output.txt  STEP2 #for i in `cat grep_output.txt` #do sed -e "s/'/'\\\\...

How to block an IP using iptables

iptables -A INPUT -s xx.xx.xx.xx -j DROP specific port:   iptables -A INPUT -p tcp -s xx.xx.xx.xx --dport PORT -j DROP allow access to an IP?   iptables -A INPUT -s xx.xx.xx.xx -j ACCEPT allow access to an IP to a specific port using iptables?   iptables -A INPUT -p tcp -s xx.xx.xx.xx --dport PORT -j ACCEPT where, xx.xx.xx.xx is the remote IP address and PORT is the port number you wish to allow/deny access to. block a scanner on your server for example “w00tw00t.at.ISC.SANS” using iptables? iptables -I INPUT -p tcp --dport 80 -m string --algo bm \ --string 'GET /w00tw00t.at.ISC.SANS.' -j DROP   Source: http://safesrv.net/quick-how-to-denyallow-ip-using-iptables/