Friday, December 18, 2009

Spring : Create instance with constructor arguments

If our java class has a constructor like this with argument.

public class Home() {
    private String name;

    public Home(String s) {
         name = s;   
    }
}

We can write our spring bean like this.

       <bean id="home1" class="<class.path>.Home">
           <constructor-arg value="My_Home"/>
       </bean>

Sunday, November 8, 2009

Cron job for linux.



For more information visit to the original site.
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Example(s)

If you wished to have a script named /root/backup.sh run every day at 3am, my crontab entry would look like as follows:

(a) Install your cronjob:
<code> # crontab -e
</code>(b)Append following entry:
<code>0 3 * * * /root/backup.sh
</code>Run five minutes after midnight, every day:<code>
5 0 * * * /path/to/command</code>
Run at 2:15pm on the first of every month:
<code>15 14 1 * * /path/to/command
</code>Run at 10 pm on weekdays:<code>
0 22 * * 1-5 /path/to/command </code>
Run 23 minutes after midnigbt, 2am, 4am ..., everyday:<code>
23 0-23/2 * * * /path/to/command
</code>Run at 5 after 4 every sunday:<code>
5 4 * * sun /path/to/command</code>

How do I disabling Email output?

By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append >/dev/null 2>&1.<br /> For example:
0 3 * * * /root/backup.sh >/dev/null 2>&1


To mail output to particluer email account let us say vivek@nixcraft.in you need to define MAILTO variable to your cron job:
MAILTO="vivek@nixcraft.in"
0 3 * * * /root/backup.sh >/dev/null 2>&1



Thursday, August 20, 2009

The BASEDIR environment variable is not defined correctly

Tomcat Issue

The BASEDIR environment variable is not defined correctly
This environment variable is needed to run this program

This will occur due to using a copy of tomcat which is packed someone else.

The solution for this is go to the bin and change the mod into 777 of all .sh file.
chmod 777 *.sh

Saturday, July 18, 2009

How to convert string date into Date object.

How to convert string date into Date object.

Date date = getDate("18/07/2009 15:15:45");

private static Date getDate(String fullDate) throws ParseException {
          SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
          df.setLenient(false); return df.parse(fullDate);
}


Wednesday, July 15, 2009

Getting the IP Address of a Hostname

Getting the IP Address of a Hostname

        try {
                InetAddress addr = InetAddress.getByName("google.com");
                byte[] ipAddr = addr.getAddress();

                // Convert to dot representation
                String ipAddrStr = "";
                for (int i=0; i<ipAddr.length; i++) {
                    if (i > 0) {
                        ipAddrStr += ".";
                    }
                    ipAddrStr += ipAddr[i]&0xFF;
                }
            System.out.println("ipAddrStr = " + ipAddrStr);
            } catch (UnknownHostException e) {
            }