Any way to detect in software from Windows that a linux app is running?

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
I'm writing software for a system that has several Windows machines and one Linux machine that runs a special communications service, all are on a small private LAN. My app is written in VB.Net and runs on what we call the Admin station, a Dell desktop, and it performs certain monitoring and alerting functions. I use Samba for writing files over to a share on the Linux box.

At times my app needs to know if the app on the Linux is running. That is, is the process currently alive over there. I have learned how to ask Windows about Services running on the local machine, but how to do that for the app on Linux?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Depends on what is running on the Linux system, by default I don't know of any sort of RPC service that will do that. I take it you can't query the special comm service directly?
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
you could use perl process modules and make a web cgi....windows res kit has a command line HTTP, so you could call the web page and parse the output.
 

cleverhandle

Diamond Member
Dec 17, 2001
3,566
3
81
Yeah, why not just open up a connection to the port and see if it responds as expected? I haven't done much network programming and never in VB, but that seems like a pretty universal approach.
 

lansalot

Senior member
Jan 25, 2005
298
0
0
Knowing if the app is running is easy, you want the ssh equivalent of "rsh host ps -ef|grep processname" (can't test, no linux handy).

Knowing if it is running as opposed to running&responding - well that depends on the way it responds, so you need to suss that one out.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Knowing if the app is running is easy, you want the ssh equivalent of "rsh host ps -ef|grep processname" (can't test, no linux handy).

That's not guaranteed to be accurate because if the process list produced by ps includes the grep command it'll match even if processname isn't in the list. pgrep should be more accurate, it's in the procps package so it should be there but I doubt it's portable to non-Linux systems.
 

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
OK, sounds like there's a starting point in there somewhere. I'm a junior programmer, I had Linux in school, I'm comfortable with ps, but I need to have my VB.Net do the checking. At certain times it will say, "Time to check and see if \\LinuxShare\application is running". How can I get it to do a ps? I know the Shell() command will do command line stuff for me in Windows. Can a command window in XP send a Unix command to a Linux box and get a reply?
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
Originally posted by: lansalot
Knowing if the app is running is easy, you want the ssh equivalent of "rsh host ps -ef|grep processname" (can't test, no linux handy).

Knowing if it is running as opposed to running&responding - well that depends on the way it responds, so you need to suss that one out.

wouldn't the ssh command just be ssh remote_user@remote_host -i keyfile {whatever command}?
 

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
A friend suggested using telnet from the Windows side and send a "ps -ax|grep appname > /results.txt" and then read from the results file. That sounds close to what I know enough stuff to do. We have a suite of .Net components called IPWorks and one of them is a Telnet component, all nicely .Net integrated.

But the problem I've hit is that the app (bought for our system from an outside developer) runs under root. I can login with telnet from XP in a command window, and make it all happen. And I can connect with the Telnet component, but cant seem to use it to login. The Telnet component has no property for User or Password that I can plug in. I'm trying to figure out how it works with responses from the telnet server on linux. There must be something coming back that asks for login and is not being seen that I can determine
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
A) don't use telnet, use ssh.
B) you should be able to parse the output of pgrep (as I mentioned before, ps is racy) without using a temp file.
 

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
and what does pgrep do? I ran it on a linux terminal (this is redhat 9) and it returned the processid. So the idea is - if it returns anything then the app is running (I dont have to know the pid in advance) and if it's not running the return will be null?
 

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
there is a windows ssh client?

This is new stuff to me, I had linux briefly in school

 

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
And again, all this is going to have to be written into a Windows Service, no user interface. The idea is to run it on a timer thread that asks the linux box once per time interval - "Is that app running?"
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
and what does pgrep do? I ran it on a linux terminal (this is redhat 9) and it returned the processid. So the idea is - if it returns anything then the app is running (I dont have to know the pid in advance) and if it's not running the return will be null?

Exactly. If you run 'pgrep blah' it'll return nothing at all since there's no process with the string blah in it's name. But, rememeber that pgrep does a substring search (actually you can probbaly use regular expressions, but that's not necessary here) so if you search for 'ash' it'll return pids for all of the 'bash' processes on the system.

there is a windows ssh client?

Yes, ssh is an open protocol so anyone is allowed to create implementations of it. It's just that MS doesn't ship Windows with one since remote CLI on Windows is pretty much useless right now.
 

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
I guess it comes back to what will I be able to do with my skill level - it's SO CLOSE to working with the IPWorks component. There MUST be a way to get it to login.

Sigh . . .
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
This is one reason why I hate VB, it's so simple in shell, perl, etc to just say $value = `ssh remote_user@remote_host -i keyfile pgrep blah` and check $value to see if there's a PID in there.
 

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
Still learning

Someone showed me about cron and I did a simple cron job that does the pgrep thing once a minute and updates the results.txt without me doing a thing. All i have to do in my Service is read the file once a minute and if there is a pid there the app is running. I'll accept that.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
But you still have to read the file on the local filesystem, how do you plan on doing that?
 

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
It's easy to read a file on the Linux box from the .Net app. We have Samba running on the Linux, and I open and read it like any other shared file on the network. I already read files that way for other purposes.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Ah, then yea the cron job is probably the simplest solution from your standpoint.
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
you can do this as as CGI module...write the shell script, put it on the web server, and have the vbscript call the webCGI and parse it's output.