LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-26-2011, 02:08 PM   #1
ch41
LQ Newbie
 
Registered: Jan 2011
Location: medan
Posts: 10

Rep: Reputation: 0
check if service is runing or not using java


hi all,
i've some trouble to write a script on java on linux to check if service(ie:smbd) is runing or not,, could you give me some example? Or if is there any source about it for me to learn? i've two days search with zero result...please help me.. Sory for some english error..
 
Old 02-26-2011, 02:26 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Would something like this be useful?

Code:
String command="ps -A -U "+System.getProperty("user.name")+" -d";
try {
      String line;
      Process p = Runtime.getRuntime().exec(command);
      BufferedReader input =new BufferedReader(new InputStreamReader(p.getInputStream()));
      while ((line = input.readLine()) != null) {
        System.out.println(line);
      }
      input.close();
    }catch (Exception err) {
      err.printStackTrace();
    }
Of course you would need to modify it to reflect for searching for smbd.
 
1 members found this post helpful.
Old 02-26-2011, 02:29 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

1. Runtime.exec ("/etc/init.d/snmpd status") to get the service current status (for example)
2. Use Process streams to read the result.

For example (pseudo code: untested):
Code:
Process process = Runtime.getRuntime ().exec ("/etc/init.d/snmpd status");
InputStream stdout = process.getInputStream ();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
...
String input = scan.nextLine();
...
 
Old 02-26-2011, 02:31 PM   #4
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Quote:
Originally Posted by paulsm4 View Post
Hi -

1. Runtime.exec ("/etc/init.d/snmpd status") to get the service current status (for example)
2. Use Process streams to read the result.

For example (pseudo code: untested):
Code:
Process process = Runtime.getRuntime ().exec ("/etc/init.d/snmpd status");
InputStream stdout = process.getInputStream ();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
...
String input = scan.nextLine();
...
That too

To add to that, to check for the example the OP posted, it would be "/etc/init.d/smb status"
 
1 members found this post helpful.
Old 02-27-2011, 12:18 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
corp769 -

You and I happened to post the same answer at the same time (your post didn't show until after I clicked "send").

I guess that proves great minds run in the same channel .

Anyway, I'm hoping the OP is squared away.
 
Old 02-27-2011, 12:20 PM   #6
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Quote:
Originally Posted by paulsm4 View Post
corp769 -

You and I happened to post the same answer at the same time (your post didn't show until after I clicked "send").

I guess that proves great minds run in the same channel .

Anyway, I'm hoping the OP is squared away.
Yes they do

I haven't programmed with java in such a long time, yet I knew what to look for.... I think it's been 6 or 7 years since I touched java. I've been messing with perl and python lately...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Runing scripts using Java arun8900 Programming 4 08-19-2010 12:26 PM
nagios check service noir911 Linux - Networking 5 07-24-2006 05:12 PM
Service check script assafde Linux - Networking 1 02-02-2006 06:46 PM
Service check script MPowers Linux - Networking 1 01-24-2006 12:42 AM
help runing a java program matt_w_lambert Programming 4 10-31-2003 10:42 AM


All times are GMT -5. The time now is 02:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration