Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

How to get the hostname of a local machine using Java

Answer:

The following codes illtsraeted how to get the hostname of the local machine using Java.

import java.net.InetAddress;

public class Test {

    public static void main(String[] args) {

        try {
            InetAddress addr = InetAddress.getLocalHost();

            // Get hostname
            String hostName = addr.getHostName();

            System.out.println(hostName);

        } catch (Exception e) {}
    }
}

Show current Postfix queue listing

Answer:

To show the current Postfix queue, you can try the command "postqueue"

# postqueue -p

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
BD7E2BF973      972 Sat Aug 27 08:57:54  no-reply@example.com
(connect to alt4.gmail-smtp-in.l.google.com[209.85.143.27]:25: Connection timed out)
                                         johndoe@gmail.com

Post a file to a server using the Curl command

Answer:

You can simulate a HTTP form post, with a file being uploaded to a remote server using the curl command.

curl -F 'photo=@/upload/image.jpg' http://example.com/upload.php

Assume the name of the form element of your upload is called "photo"

Debug and verify Postfix configurations

Answer:

A simple way to debug and verify your Postfix configurations is the use the sendmail command with the -bv flag.

Example:

# sendmail -bv username@example.com

No email will be sent using the above command, it just report after verifying each recipient address. This is very useful for testing the Postfix configurations.

Install Google Chrome in Ubuntu

Answer:

To install Google Chrome in Ubuntu, the simplest way is to us PPA

E.g.

1. Add the key and URL

# wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
# sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'

2. Install it

# sudo apt-get update
# sudo apt-get install google-chrome-stable

Done.