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.