Sunday, December 27, 2009

Windows Hard Drive Serial Number

public static String getSerialNumber(String drive) {
String result = "";
try {
File file = File.createTempFile("realhowto",".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);

String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
+"Set colDrives = objFSO.Drives\n"
+"Set objDrive = colDrives.item(\"" + drive + "\")\n"
+"Wscript.Echo objDrive.SerialNumber"; // see note
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
}
catch(Exception e){
e.printStackTrace();
}
return result.trim();
}

Execute an OS Command

public static void main (String [] args) throws IOException {

String [] Command = null;

if (System.getProperty("os.name").equals("Linux")) {
Command = new String[1];
Command[0] = "df";
}
if (System.getProperty("os.name").equals("Solaris")) {
Command = new String[2];
Command[0] = "df";
Command[1] = "-k";
}
if (Command == null) {
System.out.println("Can't find free space on this OS");
System.exit(1);
}

Process Findspace = Runtime.getRuntime().exec(Command);

BufferedReader Resultset = new BufferedReader(
new InputStreamReader (
Findspace.getInputStream()));

String line;
while ((line = Resultset.readLine()) != null) {
System.out.println(line);
}
}
}

Saturday, December 26, 2009

Simple FTP Client

private void download( String ftpServer, String user, String password,
String fileName, File destination ) throws MalformedURLException,
IOException
{
if (ftpServer != null && fileName != null && destination != null)
{
StringBuffer sb = new StringBuffer( "ftp://" );
// check for authentication else assume its anonymous access.
if (user != null && password != null)
{
sb.append( user );
sb.append( ':' );
sb.append( password );
sb.append( '@' );
}
sb.append( ftpServer );
sb.append( '/' );
sb.append( fileName );
/*
* type ==> a=ASCII mode, i=image (binary) mode, d= file directory
* listing
*/
sb.append( ";type=i" );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try
{
URL url = new URL( sb.toString() );
URLConnection urlc = url.openConnection();

bis = new BufferedInputStream( urlc.getInputStream() );
bos = new BufferedOutputStream( new FileOutputStream(
destination.getName() ) );

int i;
while ((i = bis.read()) != -1)
{
bos.write( i );
}
}
finally
{
if (bis != null)
try
{
bis.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
if (bos != null)
try
{
bos.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
else
{
System.out.println( "Input not available" );
}
}

Thursday, December 24, 2009

Setting JAVA_HOME in RHL5

Edit /etc/profile.


JAVA_HOME=/usr/java/jre1.6.0_17
export JAVA_HOME
PATH=$ORACLE_HOME/bin:$JAVA_HOME/bin:$PATH
export PATH

Saturday, December 19, 2009

Make your current web page look disabled.

If you need to make your current web page look disabled, in order to display a form or message box, simply add the following div onto your page,
and make sure you give it the following css properties as well.

div:

div id="somediv" class="opaqueDiv"


css:

.opaqueDiv{
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
filter: alpha(opacity=30);
position:fixed;
top:0px;left:0px;
background:white;
width:100%;
height:100%;


}

Monday, November 16, 2009

GlassFish Clustering Concepts.

You can have many Domains. - To Manage Separate Applications in a hosting environment.

A Domain has DAS. (Domain Administration Server)

A Domain can have many instances running. Each instance runs in its own JVM.
Each instance will belong to only one domain.
An instance can be clustered or stand-alone.
For instances to be running in a domain, it MUST have a Node Agent.
A Node Agent is for creating and managing instances, and also acts as a watchdog,..fail over stuff.

First Create a Cluster.
Then Create a Node Agent and start it.
Next create an Instance, and note: when creating it you have to specify the node agent that is running. Optionally you can
specify the cluster that you created, if you don't specify it, then it will be taken as stand alone instance.
start the instance you created.
start the cluster if it is not automatically started.

when deploying you can specify the target..to a cluster.

Note : You can share libraries across a cluster.

Monday, October 5, 2009

Setting up SSH Connection

su - root

service sshd start

or

/etc/init.d/sshd start

then make sure your firewall is open on port 22

Open flle /etc/sysconfig/iptables:
Append rule as follows:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
/sbin service restart iptables.


To disable firewall completelty
____________________________________

system-config-securitylevel

http://www.faqs.org/docs/securing/soft-netfirew.html

Friday, September 25, 2009

Setting Up SVN in Ubuntu 9.04

I found the below article quite helpful.

http://techgurulive.com/2009/01/13/how-to-install-and-configure-subversion-on-ubuntu/

To summarize:

1. Install Subversion
sudo apt-get install subversion libapache2-svn
svnadmin create /path/to/repos/project

2. Importing files to repository
svn import /path/to/import/directory file:///path/to/repos/project

here, the nano screen appeared.
cntrl x and pressed continue.

3. svn co file:///path/to/repos/project

4. create user names for multiple access.
4.1 Go to the repository you created, and that folder
edit /conf/svnserv.conf file
Uncomment the line below to use the default password file.
password-db = passwd

NOTE: In RED HAT # vim /etc/subversion/svn-authz


4.2 Next edit the passwd file.

5. Now, to access Subversion via the svn:// custom protocol, either from the same machine or a different machine, you can run svnserver using svnserve command. The syntax is as follows:

$ svnserve -d --foreground -r /path/to/repos
# -d -- daemon mode
# --foreground -- run in foreground (useful for debugging)
# -r -- root of directory to serve

eg:
svnserve -d --foreground -r /home/byorn/myrepos/


Once you run this command, Subversion starts listening on default port (3690). To access the project repository, you must run the following command from a terminal prompt:


6. To Check Out.
svn co svn://hostname/project project --username user_name
note: if checking out from your own machine...just give like
svn co svn://hostname project --username username would be sufficient.