Monday, December 16, 2013

Running perl scripts as cron job

 
              When we run perl scripts as cron job we should use the full paths of the commands inside the script.  Suppose if we are using the command  "top" inside the perl script. We need to use full path. For example: /usr/local/bin/top should be used for top command in the below server.

-----
# which top
/usr/local/bin/top
-----

Option to sort  processes in the order of memory usage

-----
/usr/local/bin/top -b -o res
-----

 Option to sort  processes in the order of CPU usage

-----
 /usr/local/bin/top -b -o cpu
-----

Wednesday, December 11, 2013

Giving access on SVN repository to existing Active Directory group ( NT group )

    

               I was trying to give access to our SVN repository for some existing windows NT group(Active directory group).  We are using SSPI module to authenticate users. I tried all the solutions available in the internet to give access to NT group but none didn't work. So I decided to write a perl script to update the group information in the SVN access file periodically.


Our httpd.conf file look like this

==================
              
  DAV svn
  SVNListParentPath on
  SVNParentPath "D:/Repositories"
  SVNIndexXSLT "/svnindex.xsl"

AuthName "svn repository"
AuthType SSPI
SSPIAuth On
SSPIDomain "DC=domain,DC=com"
SSPIOmitDomain on
SSPIUsernameCase lower
SSPIOfferSSPI On

AuthzSVNAccessFile "c:/Apache2.2/conf/svnaccess.txt"
require valid-user
  
==================


First enter the group names in C:\Apache2\conf\svnaccess.txt and
This is the script to update the access file

==================
 #!c:\Perl\bin\perl.exe
use POSIX qw/strftime/;
$CURRENT_FILE = "C:\\Apache2\\conf\\svnaccess.txt";
$file_name = "svnaccess";
$UPDATED_FILE = "C:\\Apache2\\conf\\svnaccess_tmp.txt";
$ARCHIVE_FOLDER = "D:\\svn_auth_files_old";
$GROUP_LIST_FILE = "C:\\Apache2\\conf\\grouplist.txt";
open $SVN_ACCESS, "<$CURRENT_FILE";
open $NEW_SVN_ACCESS, ">>$UPDATED_FILE";
unless (-d $ARCHIVE_FOLDER)
    {
        `mkdir $ARCHIVE_FOLDER`;
    }


while ( <$SVN_ACCESS> )
{
     
        $my_cur_line_main = $_;
        chomp($my_cur_line_main);

  
      
        $new_line = &check_group($my_cur_line_main);
        if ($new_line)
        {
        print $NEW_SVN_ACCESS "$new_line\n";
        }
        else
        {
        print $NEW_SVN_ACCESS "$my_cur_line_main\n";
        }
              
       
                  
      
        }
      
        close $SVN_ACCESS;
        close $NEW_SVN_ACCESS;
      
        $date_time = strftime('%d-%b-%Y__%H_%M_%S',localtime);
        `move $CURRENT_FILE $ARCHIVE_FOLDER\\$file_name\_$date_time\.txt`;
        `move $UPDATED_FILE $CURRENT_FILE`;
      
      
      
      
      
        sub check_group {
        $my_cur_line = $_[0];
        chomp ($my_cur_line);
        #print $my_cur_line;
        open $GROUP_LIST,  "<$GROUP_LIST_FILE"
  while ( <$GROUP_LIST> )
        {
      
                $group1 = $_;
                chomp $group1;
                #print $group1;
                if ($my_cur_line =~ /^$group1/)
            {
                    #print $my_cur_line;
                  
                    @group_members =`dsquery group DC=your,DC=domain,DC=com -name  $group1|dsget group -members`;
                    #print @group_members;
                    my @member_list;
                    foreach ( @group_members )
                {
                    $group_info = $_;
                    chomp($group_info);
                    @group_member = split (/=/,$group_info);
                    #print $group_member[1];
                    @member = split (/,/,$group_member[1]);
                    #print @member;
                    $member_uid = $member[0];
                    $member_uid =~ tr/A-Z/a-z/;
                    #print $member_uid;
                    push (@member_list, $member_uid);
                        #                print "$member[0]\n";
              
                    #print @member_list;
                }
                    $group_members = join (',',@member_list);
                    chop ($group_members);
                    $new_string = "$group1 = $group_members";
                    return $new_string;
                    #print  "$group1 = $group_members\n";
                              
                               
            }
                          
        }
      

}

==================


You can have a try.. All the best.

Thursday, October 1, 2009

Switch mail server from Postfix to qmail in Plesk

Execute the following:
#/usr/local/psa/admin/sbin/autoinstaller --select-release-current --install-component qmail

Then check "Plesk > home > Services management".

Thursday, September 10, 2009

Install subversion in RHEL 4

#up2date -l subversion
#up2date -i subversion

Thats it ;)

# svnversion --version

Sunday, August 23, 2009

Script to install mod_evasive in a Linux server (cPanel/Plesk )

#Script to install mod_evasive
#!/bin/bash


#Apache version
HTTPD=`ps aux|grep http|grep bin|head -1|awk '{ print $11}'`
VERSION=`$HTTPD -V|grep version|awk '{print $3}'|cut -d"/" -f2|cut -d"." -f1`
echo -e "\e[0;31m Apache $VERSION \e[0m is running in the server"
APACHE_CONF=`$HTTPD -V|grep HTTPD_ROOT|cut -d"=" -f2|sed s/\"//gi`\/`httpd -V|grep SERVER_CONFIG_FILE|cut -d"=" -f2|sed s/\"//g`


if [ "`grep mod_evasive $APACHE_CONF`" ]
then
echo "mod_evasive is already installed in the server"
exit
else "Starting installation of mod_evasive"
fi

echo "Downloading source..."
cd /usr/src
wget http://www.zdziarski.com/projects/mod_evasive/mod_evasive_1.10.1.tar.gz
if [ -f /usr/src/mod_evasive_1.10.1.tar.gz ]
then
tar xfz mod_evasive_1.10.1.tar.gz
cd mod_evasive
else
echo -e "\e[0;31m ERROR: Could not download source \e[0m"
fi


# Need to install httpd-devel in Plesk server
if [ -d /usr/local/psa ]
then
yum install httpd-devel*
fi

APXS=`ps aux|grep http|grep bin|head -1|awk '{ print $11}'|sed s/httpd/apxs/g`


#Add the directives in apache conf
case $VERSION

in
1) $APXS -cia mod_evasive.c ;
echo \ >> $APACHE_CONF ;
echo DOSHashTableSize 3097 >>$APACHE_CONF;
echo DOSPageCount 6 >>$APACHE_CONF;
echo DOSSiteCount 100 >>$APACHE_CONF;
echo DOSPageInterval 2 >>$APACHE_CONF;
echo DOSSiteInterval 2 >>$APACHE_CONF;
echo DOSBlockingPeriod 600 >>$APACHE_CONF;
echo \ >>$APACHE_CONF;;

2) $APXS -cia mod_evasive20.c ;
echo \ >> $APACHE_CONF ;
echo DOSHashTableSize 3097 >>$APACHE_CONF;
echo DOSPageCount 6 >>$APACHE_CONF;
echo DOSSiteCount 100 >>$APACHE_CONF;
echo DOSPageInterval 2 >>$APACHE_CONF;
echo DOSSiteInterval 2 >>$APACHE_CONF;
echo DOSBlockingPeriod 600 >>$APACHE_CONF;
echo \ >>$APACHE_CONF;;
*) echo -e "\e[0;31mERROR: Apache version is not compatible\e[0m"
esac

#Restart Apache
service httpd restart
echo -e "\e[0;31m Mod_evasive is installed successfully..\e[0m"

Tuesday, June 30, 2009

How to know the version of Debian installation.

----------------
1) #cat /etc/issue
2) #cat /etc/debian_version
----------------

Tuesday, June 16, 2009

install postfix with postgresql support in centos 5

Download the RPM from the following link - 

#wget http://mirror.centos.org/centos/5/centosplus/i386/RPMS/postfix-2.3.3-2.1.centos.mysql_pgsql.i386.rpm

#rpm -ivh postfix-2.3.3-2.1.centos.mysql_pgsql.i386.rpm

done :)

check for postgresql support -

#postconf -m|grep pgsql

pgsql