About Me

My photo
Working as Technical Lead in CollabNET software private limited.

Thursday 26 February, 2009

Recursive shell command s

I was searching for macking the commands work recursively.

Below is the way to do it.

MIGRATION_CONFIG_FILE="$(dirname $(dirname $(readlink $0)))"/$CONFIGURATION_FILE.

Monday 16 February, 2009

Splitting a patch file

Some times the patch file needs to be splitted to individual files for easy handling.

Below is the command to do that, cut the patch file matching pattern "Index:".

csplit artf21810.diff /Index:/ {*}

Friday 13 February, 2009

Script to delete folder in a loop

#!/bin/sh
i=0
while [ $i -le 40 ]
do
folder="psr-pub-$i"
#chown apache:apache $folder -R
rm -rf $folder
i=`expr $i + 1`
done

Shell script to connect postgress in a loop

i=211
while [ $i -le 250 ]
do
folder="psr-pub-$i"
echo "Starting processing $folder."
./svnmapping.sh $folder
echo "Done with $folder"
i=`expr $i + 1`
done


projectName=$1
userId="user1308"

DBConnect="psql -d psrdb -U psruser --tuples-only --single-line"

date=`date +"%F %T"`
projId=`echo "select id from project where path='projects.$projectName'" | $DBConnect`
projId=`echo $projId`

parent_folder_id=`echo "select id as parent_folderid from folder where path = 'scm' and project_id='$projId'" | $DBConnect`
parent_folder_id=`echo $parent_folder_id`

nextscm_id_query="select max(substring(id from (char_length('reps')+1))) from scm_repository"
primaryId_query="select id from objecttype where application='Scm' and name='Repository'"
secondaryId_query="select id from objecttype where application='Scm' and name='Commit'"

nextscm_id=`echo $nextscm_id_query | $DBConnect`
nextscmId=`echo $nextscm_id`
nextscmId=reps`expr $nextscmId + 1`
primaryId=`echo $primaryId_query | $DBConnect`
primaryId=`echo $primaryId`
secondaryId=`echo $secondaryId_query | $DBConnect`
secondaryId=`echo $secondaryId`

insertscm="insert into scm_repository values('$nextscmId', 'exsy1002', '/svnroot/$projectName', 'f')"
insertfolder="insert into folder values ('$nextscmId', 'scm.$projectName', '$projectName', '$projectName', '100', '$date+05:30', '$date+05:30','f', '$primaryId', '$secondaryId', '$userId', '$userId', '$parent_folder_id', '$projId', '0')"

scm=`echo $insertscm | $DBConnect`
fol=`echo $insertfolder | $DBConnect`

echo $scm" "$fol

Thursday 5 February, 2009

How to set alias name for network machines

Simple thing but avoids our repetative daily work.

To set alias name for your frequently used machine.

#Go to /etc/hosts
vi /etc/hosts
#Make an entry for your machine
#IPAddress Hostname Alias
127.0.0.1 connectmachine.com connect
#Restart your network
/etc/rc.d/init.d/network restart

Once it's done. do a ping to check it up

ping connect