Tuesday, August 31, 2010

how to test smtp account with ruby

To check smtp account working or not use below ruby script for smtp verification save the file with ruby extension



require 'net/smtp'
#

message = <<>
To: A Test User
Subject: SMTP e-mail test
This is a test e-mail message.
MESSAGE_END

Net::SMTP.start('domain.com',25,'doamin.com','chetu','amin') do |smtp|
smtp.send_message message, 'chetu_242000@gmail.com',
'chetan.muneshwar@incom'
end

Friday, August 27, 2010

How to tag Git code

#! /bin/bash

tag_me()
{
tag_name=$1
message=$2
TIME=`date +%Y-%m-%d-%H-%M`
git tag -d $tag_name
git tag -a -f -m "$message" $tag_name-$TIME
git push origin tag $tag_name-$TIME
}


if [ $# -ne 2 ] ;then
echo 1>&2 Usage: $0 tag_name message
exit 127
fi

tag_me $1 $2



usage :

./tag_scripts tag_name messages

How to branch Git code and push to origin

#!/bin/bash
# git-create-branch
# git
if [ $# -ne 1 ]; then
echo 1>&2 Usage: $0 branch_name
exit 127
fi

branch_name=$1
git push origin origin:refs/heads/${branch_name}
git fetch origin
git checkout --track -b ${branch_name} origin/${branch_name}
git pull

============================================================
Usage :

./branching.sh branch_name_desired

Recover data from mysqlbinlog

if server crash and after restore mysqlbinlog not get recovered there is possibility of loosing data. still we can get important data with restoring from bin-log.

* Guess the the time of crash copy all bin-log files to separate folder ,in-case if you have backup of old date you need to select only those bin-log file having date after the dump taken .

* Run the command as such [better to go with one by one db recovery] .

/usr/local/mysql/bin/mysqlbinlog --database=pottytraining mysql-bin.000033 mysql-bin.000034>/opt/pottytraining.sql

* login to mysql prompt

mysql> use pottytraining;
mysql> source /opt/pottytraining.sql;


* Cool see the data.


Thanks

monitor mongrel for rails application

#! /bin/bash
# ChetanM chetan.muneshwar@gmail.com

# Add to this script to /usr/bin/path
# Add */1 * * * * /usr/bin/monome in crontab

# please specify path of rails ROOT eg /home/myapp/ [not /home/myapp/public]
RAILS_ROOT=
cd $RAILS_ROOT/
pii()
{
PROCNAME=$1
PIDS=`ps -efa | grep $PROCNAME | grep -v grep | awk '{ print $2 }'`
for ff in $PIDS
do
echo "$ff"
done
}
mongrel_array=(3078 3079 3080 )
for (( i = 0 ; i < ${#mongrel_array[*]}; i++ ))
do
pii tmp/pids/mongrel.${mongrel_array[i]}.pid >/tmp/dat$$$

if [ "`cat /tmp/dat$$$`" == "" ] ;then
rm -rf tmp/pids/mongrel.${mongrel_array[i]}.pid
mongrel_rails cluster::restart --only ${mongrel_array[i]}
else
echo "accha hai "
fi
done