Archives for

Using Grep Efficiently Inside SVN Repositories

I’ve had issues grepping for text inside SVN repositories. The main issue is that grepping inside SVN codebases will return binary and .svn results. I’ve run into this probably most frequently when using Mac OS X. For some reason the –exclude argument doesn’t work for me and –exclude-dir is not supported in a default Mac OS X installation ( at least on Lion ).

Here’s an example of output from grep that’s irrelevant and should be removed:

Binary file bin/classes/com/android/Class.class matches
src/com/android/.svn/text-base/Dialog.java.svn-base:

So instead of using the –exclude argument, I’ve chosen the -v option or –invert-match

#!/bin/sh
if test -z "$1"
then
          echo "1st argument must be set to your search term";
else
        grep -R $1 * | grep -v 'svn' | grep -v 'Binary*'
fi

You can copy and paste this code and have it be globally accessible in the Mac OS X terminal by doing the following. If /usr/local/bin has not been created yet then issue this command:

NOTE: I'm using sudo to execute these commands as the relevant directories are owned by root.

# sudo mkdir -p /usr/local/bin

Otherwise create the shell script

# sudo vim /usr/local/bin/svngrep

Then cd to the directory and make sure the file is executable.

# cd /usr/local/bin/
# chmod 755 svngrep

Now open a new terminal window and cd to the area where you want to search in your SVN repository. From there call the script like so and pass your search argument as the first and only argument.

svngrep MyMethod

Additional search terms can be excluded by adding more | grep -v 'search-term' clauses.

Read More

WebDAV Breaks After Installing WordPress

If you are using WebDAV with WordPress then most likely the WordPress .htaccess file will break the WebDAV configuration. One basic work around for this is to turn off the Apache Rewrite Engine for the directories that you want to enable WebDAV for.

# cd into a directory within your html root where you want to enable WebDAV
$ cd /var/www/path/source

# then create a .htaccess file and disable the Rewrite Engine
$ vim .htaccess

# paste this into the vim file:

<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>


Then follow the same steps for any other directories you would like to enable.

Read More

Centos New MySQL Package Names and PHP/MySQL conflicts

I’m noticing in my version of Centos on AWS that there are new package names for the installation of mysql:

yum install MySQL-client-community MySQL-devel-community MySQL-server-community

In addition there is a conflict in getting php to work with mysql.

Install the MySQL-shared-compat-5.1.47-1.rhel4.i386.rpm, it resolves the need for the old mysql lib dependencies for php-mysql, install first this rpm and after this, php-mysql. So performing these yum installs should get php and mysql working:

yum install MySQL-shared-compat
yum install php-mysql

Read More

iptables firewall script for bittorrent-curses

This is a basic iptables firewall script for downloading bittorrents:


#!/bin/sh
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
#modprobe ip_conntrack
#modprobe ip_conntrack_ftp

# Setting default filter policy
#iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT

# Unlimited access to loop back
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# Allow UDP, DNS and Passive FTP
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

#allow bittorent incomming client request
iptables -A INPUT -p tcp --destination-port 6881:6999 -j ACCEPT

#Uncomment below to allow sshd incoming client request
#iptables -A INPUT -p tcp -dport 22 -j ACCEPT

# DROP everything and Log it
iptables -A INPUT -j LOG
#iptables -A INPUT -j DROP

Read More