Friday, July 31, 2009

wget with basic authentication.

Here's how you download a file from internet which is secured by basic authentication. Replace myusername, mypassword with your own username and password.


wget http://download_file --http-user=myusername --http-passwd=mypassword

Wednesday, July 29, 2009

Hudson init script for Ubuntu 9.04

Hudson init script for ubuntu 9.04. This is available on hudson's website too.

http://wiki.hudson-ci.org/display/HUDSON/Installation+and+Execution

This is what worked for me. The one hudson website is for linux. This you can use as is without modifications (except for "RUN_AS") on ubuntu


#!/bin/sh

DESC="Hudson CI Server "
NAME=hudson
PIDFILE=/var/run/$NAME.pid
RUN_AS=sysadm

d_start() {
start-stop-daemon --start --quiet --background -m --pidfile $PIDFILE --chuid $RUN_AS --exec /usr/bin/java -- -Dhudson.scm.CVSSCM.skipChangeLog=true -jar /opt/hudson/hudson.war
}

d_stop() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE
if [ -e $PIDFILE ]
then rm $PIDFILE
fi
}

case $1 in
start)
echo -n "Starting $DESC: $NAME "
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME "
d_stop
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME "
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "usage: $NAME {start|stop|restart}"
exit 1
;;
esac

exit 0

SSH without Password

I got information from this site

http://www.csua.berkeley.edu/~ranga/notes/ssh_nopass.html

SSH Without a Password

The following steps can be used to ssh from one system to another without specifying a password.
Notes:

* The system from which the ssh session is started via the ssh command is the client.
* The system that the ssh session connects to is the server.
* These steps seem to work on systems running OpenSSH.
* The steps assume that a DSA key is being used. To use a RSA key substitute 'rsa' for 'dsa'.
* The steps assume that you are using a Bourne-like shell (sh, ksh or bash)
* Some of this information came from:
http://www.der-keiler.de/Mailing-Lists/securityfocus/Secure_Shell/2002-12/0083.html

Steps:

1.

On the client run the following commands:


$ mkdir -p $HOME/.ssh
$ chmod 0700 $HOME/.ssh
$ ssh-keygen -t dsa -f $HOME/.ssh/id_dsa -P ''


This should result in two files,


$HOME/.ssh/id_dsa (private key) and
$HOME/.ssh/id_dsa.pub (public key).


2.

Copy $HOME/.ssh/id_dsa.pub to the server.


3.

On the server run the following commands:


$ cat id_dsa.pub >> $HOME/.ssh/authorized_keys2
$ chmod 0600 $HOME/.ssh/authorized_keys2


Depending on the version of OpenSSH the following commands may also be required:


$ cat id_dsa.pub >> $HOME/.ssh/authorized_keys
$ chmod 0600 $HOME/.ssh/authorized_keys



An alternative is to create a link from authorized_keys2 to authorized_keys:


$ cd $HOME/.ssh && ln -s authorized_keys2 authorized_keys


4.

On the client test the results by ssh'ing to the server:


$ ssh -i $HOME/.ssh/id_dsa server



5.

(Optional) Add the following $HOME/.ssh/config on the client:


Host server
IdentityFile ~/.ssh/id_dsa


This allows ssh access to the server without having to specify the path to the id_dsa file as an argument to ssh each time.

HUDSON: THINGS TO REMEMBER [Skip Change Log]

While starting hudson use:
java -Dhudson.scm.CVSSCM.skipChangeLog=true -jar hudson.war

This makes sure that hudson skips computing change log. Computing change log option is
slow for one thing and caused a lot of problems while I was setting it up in our projects.


Saturday, July 11, 2009

Carnatic Music Website.

http://www.ecse.rpi.edu/Homepages/shivkuma/personal/music/index.html

Professor Shiv Kumar Kalyanaraman's carnatic music archive. Wonderful website for carnatic music.

Monday, June 29, 2009

Move sqlserver tables to dbo user

SELECT 'ALTER SCHEMA dbo TRANSFER ' + SCHEMA_NAME(schema_id) + '.' + name
FROM sys.tables
WHERE schema_id != SCHEMA_ID('dbo');

Sunday, June 21, 2009

Starting JavaDB (Derby) in glassfish.

I was following sahoo's Blog for creating an enterprise application with ejb3.0.
http://weblogs.java.net/blog/ss141213/archive/2005/12/using_java_pers.html

Ran into problem since JavaDB isn't started automatically when glassfish starts.

Error was "Error connecting to server localhost on port 1527 with message Connection refused: connect."

Solution:

You will have to issue below command to start derby database:

GlassFishHome/bin/> asadmin start-database

Hope this helps someone having similar issues.

Saturday, June 20, 2009

Samba File Sharing Ubuntu

SSH server is disabled by default in ubuntu. From package manager select & install ssh-server.

Samba File Sharing:

Setup up username & password:
smbpasswd -a
you'll be prompted to set the password.


Restart Samba service to take effect: [Just for good measure]
sudo /etc/init.d/samba restart

UBUNTU setting up environment variables.

Use file /etc/bash.bashrc to setup new environment variables.


Do not use: /etc/profile
Do not use: /etc/environment file might work too.

Procedure:

1. Edit: /etc/bash.bashrc
2. Add this line to the end of the file. This sets JAVA_HOME

export JAVA_HOME=/usr/lib/j2sdk1.5-sun/

Linux helpful commands

List of processes:
Solaris stats: prstat
Redhat stats: top


COMMON:
more /proc/version --- To see which version of linux
cat /proc/cpuinfo
cat /proc/meminfo

Creating symbolic link (shortcut in *unix) :
ln -s file_name shortcutname

Placing java in your path:
create link to the version of java into /usr/bin

Linux Runlevels:
who -r (gives run level of the system)
vi \etc\inittab (shows you the runlevel system is starting)

cd \etc\rc5.d (start up scripts for run level 5. K's represent donot start. S's represent start)
cd \etc\rc3.d (start up scripts for run level 5. K's represent donot start. S's represent start)
mv K36mysqld S36mysqld

ln -s ../init.d/jboss S36Jboss
mv S36Jboss K36Jboss
rm K36Jboss

WGET: [Connect to internet and download a file]

wget http://download_file_url

SQL to drop an index on table.

SQLServer:
DROP INDEX address.ix_address_loc;

Syntax for Microsoft SQLJet (and Microsoft Access):
DROP INDEX index_name ON table_name

Syntax for IBM DB2 and Oracle:
DROP INDEX index_name

Syntax for MySQL:
ALTER TABLE table_name DROP INDEX index_name

SQL for alter column

Sqlserver:

alter table customer alter column customer_name varchar(50);

Oracle Timestamp

update customer set timestamp=to_date('1998/05/31:12:00:00AM', 'yyyy/mm/dd:hh:mi:ssam') where customer_id=48303

More Info:
http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html

DB2 Timestamp

SELECT STATEMENT:
select count(*) from customer where timestamp >='2010-01-01-00.00.00';

UPDATE (OR) INSERT STATEMENT:
update customer set timestamp=('2011-01-01-00.00.01.000000') where timestamp='2010-01-01-00.00.00';

Sql Server timestamp field

INSERT (OR) UPDATE STATEMENTS:

insert into customer (customer_id,timestamp) values (17982698, '2005-10-17T00:00:00.0');


SELECT STATEMENTS:

select count(*) from customer where timestamp >= convert(datetime, '2006/10/01') and issue_date <=convert(datetime, '2007/09/30');

Sql Current Timestamp.

For mysql, sqlserver, even db2 : current_timestamp

For oracle: sysdate

For mysql (one more function): now()

MySQL mysqldump tablename.MYD not found (Errcode: 24) when using LOCK TABLES

In mysql 4.1 --opt option of mysqldump was made default.

This makes mysql to LOCK TABLES.

SOLUTION:
Use --skip-lock-tables to disable.

Creating MySql Database & Setting up users.

Creating mysql Datbase:
1. At mysql command prompt issue command

create database <>;

2. Giving all users access to all the datbases from the server.

GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

3. Giving all users access to all the datbases from remote machines. '%' in the query signifies that.

GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

4. VERY VERY IMPORTANT DO NOT FORGET:
FLUSH PRIVILEGES;

LINUX MYSQL GOTCHAS

1. bind-address : If your server's ip doesn't change. Might want to make it your server's ip address. Just makes it easier to troubleshoot connectivity issues.

2. Have to have this under mysqld [this disables mysql's case sensitivity. This is only a feature on *unix operating systems. Telling you it can be quite annoying...]
lower_case_table_names = 1

Other key parameters under [mysqld] which can be quite handy.

key_buffer = 128M
max_allowed_packet = 5GB
transaction_isolation = READ-UNCOMMITTED [Especially when working with some persistence middleware provider like ejb2.1 app servers.]

3. /etc/mysql/my.cnf - Location of configuration file

4. /etc/init.d/mysql start - Starts mysql
5. /etc/init.d/mysql stop - Stops mysql
6. /etc/init.d/mysql restart - Restarts mysql.

How to import and export mysql database?

This assumes that mysql is in your classpath. Replace "dbname" in the below command with your own database name.

mysqldump -u root -p dbname > dump.sql (export)

mysql -u USER -p dbname < dump.sql (import)

Saturday, January 10, 2009

Code Snippet posting in Blogger using Syntax Highlighting

Finally able to get code posting in Blogger working.
This url helped me get there http://blog.gpowered.net/2007/07/howto-post-code.html


public class HelloWorld {
/**
* @Copyright Sarat Dontula :-)
*/
public static void main(String[] args)
{
System.out.println("Hello World");
}
}


What worked for me . In Blogger Layout -> Edit HTML -> After <head> tag place below code. Change the host name.


<link href='http://sdontula.googlepages.com/SyntaxHighlighter.css' rel='stylesheet' type='text/css'/>


Just before <body> place below code
 
<script language='javascript' src='http://sdontula.googlepages.com/shCore.js'/>
<script language='javascript' src='http://sdontula.blogspot.com/shBrushCSharp.js'/>
<script language='javascript' src='http://sdontula.blogspot.com/shBrushXml.js'/>
<script language='javascript' src='http://sdontula.blogspot.com/shBrushPython.js'/>
<script language='javascript' src='http://sdontula.blogspot.com/shBrushXml.js'/>
<script language='javascript' src='http://sdontula.blogspot.com/shBrushPhp.js'/>
<script language='javascript' src='http://sdontula.blogspot.com/shBrushJScript.js'/>
<script language='javascript' src='http://sdontula.googlepages.com/shBrushJava.js'/>




Again google should make it easy for developers to post code. This is just insane :-(

Blogger Code Styling & Display.

Found below url to style code on blogger.

http://rias-techno-wizard.blogspot.com/2008/08/display-css-codes-and-scripts-in-unique.html

I tried using syntaxhightlighting from http://code.google.com/p/syntaxhighlighter/ using this blog post http://www.fromjavatoruby.com/2008/10/ruby-syntax-highlighting-in-blogger.html without much luck.

I tried to host the .js and .css scripts on google page creator. May be google page creator doesn't serve resources if it sees some other domain is requesting it. (Remote Hot Linking). Will have to find out some other way.

It is crazy that blogger doesn't provide something out of the box to display code snippets. Driving me nuts !!!!

Friday, January 9, 2009

Apache Redirection

Uncomment below three lines in apache/conf/httpd.conf file:


LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so


Add below lines lines to httpd.conf:


RewriteEngine on
ProxyRequests Off

Order allow,deny
Allow from all

#Actual Redirection Code Starts
RewriteRule ^/customer-url$ customer-url/ [R]
ProxyPass /customer-url/ http://localhost:8080/customer-url/
ProxyPassReverse /customer-url/ http://localhost:8080/customer-url/


Above we are making apache accept requests on port 80 for a server which is serving web pages on 8080. It mean http://localhost/customer-url gets it's pages from http://localhost:8080/customer-url .

How to test if a machine has access to the smtp server

This url: http://support.microsoft.com/kb/304897
helps us in testing if server
is allowed to relay etc..

Basically you do:
1. telnet servername port
2. EHLO
3. RSET

(YOU SHOULD SEE MESSAGE AS A RESULT:
250 2.0.0 Resetting)

4. MAIL FROM:UserName@DomainName.com
(use an email belonging to the domain)

5. RCPT TO:RecipientName@DomainName.com
(use email belonging to the domain)

6. QUIT (TO EXIT)

Above should send out an email without errors.
This should tell us if we can configure email
properly.