Tuesday, October 30, 2012

Delete Files Older Than X Days on Linux

This Blog is for those who wants to delete files older than X days using single command. The find utility on linux allows you to pass in a bunch of interesting arguments, including one to execute another command on each file. We will use this in order to figure out what files are older than a certain number of days, and then use the rm command to delete them.

Command Syntax
 find /path/to/files* -mtime +7 -exec rm {} \;

Note: that there are spaces between rm, {}, and \;

Explanation
  • The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
  • The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.
  • The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.
This should work on Redhat, CentOS, Ubuntu, Suse or pretty much any version of Linux.

Monday, July 9, 2012

SSH is slow to make a connection

SSH is slow to make a connection


I just installed RHEL 6.2, and whenever I try to SSH into my servers it's very slow. Before it displays the password prompt, it can take between 40 seconds and 60 seconds.

I found the solution of it.
This is slow because the OpenSSH daemon uses DNS to run a reverse lookup on the client hostname to make sure it's valid.
sudo vi /etc/ssh/ssh_config
 
Comment out the following lines 
#GSSAPIAuthentication yes
#GSSAPIDelegateCredentials no
 
OR

add this:

UseDNS no
 
Restart sshd deamon 

 

Thursday, June 28, 2012

Alfresco Authentication Subsystems LDAP Authentication Chain

Alfresco 3.2 and later has the concept of subsystems.
Here I am describing the LDAP Authentication Chain.
How to configure more than one LDAP Authentication in Alfresco Authentication Chain subsystems.


Example:
Environment I used is Linux


Edit your alfresco-global.properties file and add


authentication.chain=ldap1:ldap,ldap2:ldap

Create Folder
Go to Folder



 

$TOMCAT_HOME/shared/classes/alfresco/extension/

mkdir -p subsystems/Authentication/ldap/ldap1
mkdir -p subsystems/Authentication/ldap/ldap2

Then copy  
$TOMCAT_HOME/webapps/alfresco/WEB-INF/classes/alfresco/subsystems/Authentication/ldap/ldap-authentication.properties

To 

$TOMCAT_HOME/webapps/alfresco/WEB-INF/classes/alfresco/subsystems/Authentication/ldap/ldap-authentication.properties
and
$TOMCAT_HOME/shared/classes/alfresco/extension/subsystems/Authentication/ldap/ldap1/ldap-authentication.properties


You can then edit the properties for ldap1 and ldap2 as required to complete the configuration. 

Wednesday, June 13, 2012

Apache mod_rewrite and examples

Apache mod_rewrite and examples

What is mod_rewrite? Mod Rewrite allows you to change the URL that everyone sees when they visit your domain or a specific address. Just add the code to your .htaccess file or in Virtual Host area.

EXAMPLES
#Specify a default home page (index page)
DirectoryIndex home.html
#Allow only specified IPs to access your site
deny from all
allow from 64.95.219.140
allow from 210.23.45.67
# Redirect all pages from olddomain.com
# to newdomain.com
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^olddomain.com$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
# Block traffic from multiple referrers
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} badsite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} badforum\.com [NC,OR]
RewriteCond %{HTTP_REFERER} badsearchengine\.com [NC]
RewriteRule .* - [F]
#Do not allow these file types to be called
RewriteEngine on
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|exe|swf)$ - [F,NC]
#Prevent subfolder loading. This goes
# in htaccess for the primary domain
RewriteCond %{HTTP_HOST} ^primary\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.primary\.com$
RewriteRule ^addon\.com\/?(.*)$ "http\:\/\/www\.addon\.com\/$1" [R=301,L]
# Never use www in the domain
# Replace 'example.com' with your domain name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?example\.com)$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
#Prevent subdomain name loading.
#This goes in htaccess for the primary domain
RewriteCond %{HTTP_HOST} ^subname\.primary\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.subname\.primary\.com$
RewriteRule ^(.*)$ "http\:\/\/www\.addon\.com\/$1" [R=301,L]
# Always use www in the domain
# Replace 'example.com' with your domain name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z.]+)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? http://www.%1example.com%{REQUEST_URI} [R=301,L]
# Set a default home directory, (this subfolder always loads)
# Replace 'folder' with your subfolder name
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ /folder/ [R=301,L]
</IfModule>
# Rename a directory and force visitors to the new name
# Replace 'old' with your old folder name
# Replace 'new' with your new folder name
RewriteEngine on
RewriteRule ^/?old([a-z/.]*)$ /new$1 [R=301,L]
# Always use https for secure connections
# Replace 'www.example.com' with your domain name
# (as it appears on your SSL certificate)
RewriteEngine On
RewriteCond %{SERVER_PORT} 100
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]