Archive

Posts Tagged ‘scripts’

Memcached Pool Bash Start Script

November 14th, 2008

If you installed Memcached using Yum under the RedHat flavor of Linux, they have this really nice init.d scripts for starting and stopping Memcache. I modified it in order to support creating a bunch memcache instances using contiguous ports. What’s great is that only the “start” script has to be modified since the “stop” script uses a special RedHat function, killproc, which can accept a program name or path and kill all instances of that program. I’m still a noob at bash scripts but here is my only changes:

NUMBUCKETS=3 #only new value needed
start() {
    for ((i=1;i<=$NUMBUCKETS;i+=1)); do
        FULLPORT=${PORT}${i}
        echo -n $"Starting $FULLPORT ($prog): \n"
        daemon $prog -d -p $FULLPORT -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS
        RETVAL=$?
    done
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
    return $RETVAL
}

linux, programming , , , , , , , , , ,

Useful Linux Commands: Find and Search

September 1st, 2008

Learning Linux commands is probably the largest hump anybody new to Linux faces. Over the last year, I’ve compiled some useful, and somewhat non-obvious scripts that are really helpful to me on a weekly basis. Here are commands that deal with finding files and searching for text within a file:

Find and delete a directory:

find /PATH/TO/DIR -type d -name SEARCH -exec rm -rf {} \;

Find and delete a file:

find /PATH/TO/DIR -name SEARCH -exec rm -rf {} \;

Search within files:

 grep -r "SEARCH" *.EXTENSION /PATH/TO/DIR

Find and search within files:

find /PATH/TO/DIR -name "SEARCH" | xargs -I{} grep -H SEARCH {}

For more advanced options there’s always:

man find
man grep

linux , , , , , , , , , , , , ,