0

Following this post http://blog.zwiegnet.com/linux-server/get-centosred-hat-original-system-install-date/ I would like to get the Linux installation date.

Process p = Runtime.getRuntime().exec("rpm -qi basesystem");

Can you tell me how I can execute the command and capture only the installation date as show into the post.

I want to get the complete output and filter the content using Java. And the final result should be something like this for example:

Thu 28 Nov 2013 06:01:06 PM EST
David says Reinstate Monica
  • 18,041
  • 20
  • 73
  • 118
user1285928
  • 1,140
  • 26
  • 93
  • 143

1 Answers1

2

Read the input stream and parse it:

Process proc = Runtime.getRuntime().exec("rpm -qi basesystem");
InputStream stdin = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stdin);
BufferedReader br = new BufferedReader(isr);

String line = null;
Date date = null

while ( (line = br.readLine()) != null) {
  // check each line for the date you need
  // set date
  // break;
}
BetaRide
  • 15,373
  • 29
  • 90
  • 165
  • Your answer is good but just what I needed is provided as comment. Could you add some more code example about the while loop, please? – user1285928 Apr 28 '14 at 13:37