Wednesday, December 29, 2010

Run Rails2.x and Rails3 Application with Passenger under RVM Ruby Environment .

Create  Add this  in config/setup_load_paths.rb


if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
  begin
    #puts ENV['MY_RUBY_HOME']
    rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
    rvm_lib_path = File.join(rvm_path, 'lib')
    $LOAD_PATH.unshift rvm_lib_path
    require 'rvm'
    RVM.use_from_path! File.dirname(File.dirname(__FILE__))
  rescue LoadError
    # RVM is unavailable at this point.
    raise "RVM ruby lib is currently unavailable."
  end
end


Specify The rvm ruby under application virtualhost .

e.g:

 LoadModule passenger_module /home/deploy/.rvm/gems/ruby-1.9.2-p0/gems/passenger-3.0.2/ext/apache2/mod_passenger.so
 PassengerRoot /home/deploy/.rvm/gems/ruby-1.9.2-p0/gems/passenger-3.0.2
 PassengerRuby /home/deploy/.rvm/environments/ruby-1.9.2-p0


All done :


Run apache under sudo'er from user which is set with RVM environment.

Friday, December 24, 2010

Clamav Getway Antivirus c-icap Setting For squid.conf

icap_enable          on
icap_preview_enable  on
icap_preview_size    128
icap_send_client_ip  on
icap_service         service_avi_req reqmod_precache 0 icap://localhost:1344/srv_clamav
icap_service         service_avi respmod_precache 1 icap://localhost:1344/srv_clamav
icap_class           class_antivirus service_avi service_avi_req
icap_access          class_antivirus allow all

Nmap To Discover Network IP,Openport,OS Type IN XML Format

#! /bin/bash

ETHERNET=eth0

HostList=(`arp -vni $ETHERNET |cut -d " " -f 1 |grep -r 192 |xargs`)

for (( i = 0 ; i <= ${#HostList[*]} ; i++ ))
    do
    nmap  -F -O -o2 --osscan-limit -oX ${HostList[i]}_$i.xml  ${HostList[i]}
done

Bandwidthd CDF File Processing

#! /bin/bash

user_array=`cat log.*.cdf  |cut -d , -f 1 |sort -u |xargs`

for B in $user_array
 do
c=2

echo -e "For the IP  $B"
echo "" > /tmp/port$$$
while [ $c -le 16 ]
     do
    cat log.*.cdf |grep $B |cut -d , -f $c |xargs >/tmp/ele$$$
    I=0
    for N in `cat /tmp/ele$$$`
    do
        I=`expr $I + $N`
    done
    echo $I >>/tmp/port$$$
        (( c++ ))
     done
     sleep 2
    echo -e "\t  `cat /tmp/port$$$ |xargs`"
done
   rm -rf *.cdf
    /etc/init.d/bandwidthd restart

How To Keep Track On Disk Usage @Linux

#! /bin/bash
# chetan.muneshwar@gmail.com
# script to get disk space status on multiple instances and alert Admin


bulk_data=(`df -Ph | grep -r '/' | awk '{ printf "%s-%s-%s-%s ",$3,$4,$5,$6  }'`)

for ((  i = 0 ;  i < ${#bulk_data[*]};  i++  ))
            do
threshold="`echo ${bulk_data[i]}|cut -d "-" -f 3|cut -d "%" -f 1` "


        if [ $threshold -le 0 ] ; then
                shm_val="`echo ${bulk_data[i]}|grep -r 'shm'`"
                if [ "$shm_val" == "" ] ; then
                    echo "SERVER ${bulk_data[i]} " | mail -s " Disk vol fuLL ISHY-SERVER " chetan.muneshwar@labs.net -c shrikant.lokhande@labs.net
                else
                   echo ""
                fi
        else
           if [ $threshold -le 90 ] ;then
             echo ""
           else
                  echo "SERVER  ${bulk_data[i]} " | mail -s " Disk vol warning ISHY-SERVER   " chetan.muneshwar@labs.net -c shrikant.lokhande@labs.net
            fi
        fi
done
Finally add cronjob : * * * * * /usr/bin/DISK