Checking to see if windows service is running


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking to see if windows service is running
# 1  
Old 11-29-2017
Checking to see if windows service is running

Hi

I have created a PowerShell script which successfully checks whether windows service pgsql-9.2 is running.

I have tried to call that PowerShell script with a shell/bash script within a LINUX machine but have been unsuccessful.

Is there a way of a shell/Perl script to check whether a windows service is running?

Many Thanks
# 2  
Old 11-29-2017
I regret that my crystal ball is a bit cloudy today. I think there was a strong frost yesterday and that's knocked it off a bit.

Please can you show us the code (wrapped in CODE tags) you are trying to run and how you are calling it to give us a chance to help you.



Thanks, in advance,
Robin
# 3  
Old 11-29-2017
See also the thread from two weeks ago: Execute powershell script with UNIX which seems to be closely related (if not a duplicate) to this discussion.
# 4  
Old 11-29-2017
Hi

Powershell Script:

Code:
#Alex Simpson
#Script to check the status of the Postgres DB

#function to check service status and restart
function FuncCheckService

{
	$ServiceName = 'pgsql-9.2'
	$arrService = Get-Service -Name $ServiceName

		if ($arrService.Status -eq 'Running')
     			{ 
         			Write-Output "$ServiceName service is running"
     			}
		else
   			  { 
        			 Write-Output "$ServiceName service is not running"
     			}
			}

#start transscript to log details
 Start-Transcript -Path "C:\Documents\CheckPostgresService.log" -Append -IncludeInvocationHeader

#Call function with EM service as a parameter
 FuncCheckService pgsql-9.2

#stop logging
 Stop-Transcript

This works fine and does what I need it to do.

I want to be able to in a shell script call the PowerShell script to execute or rewrite this script within a shell script to check whether the windows service is running but not 100% sure if this is possible.

Cheers
Alex
# 5  
Old 11-29-2017
Are you trying to control a windows system remotely? Look into Windows terminal services.
# 6  
Old 11-30-2017
Hi Corona688

We have a internal monitoring tool which is UNIX/LINUX based and to retrieve metrics results it needs to be used within the UNIX/LINUX system.

As the service is a windows service I have wrote a powershell script to check whether the service is running. However I am not sure how to get this working on the UNIX/LINUX system

Cheers
Alex
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Checking if service is running

Hi, For audit reasons, I need to stop the web server service in some Solaris servers. The port that is listening for this service is port 10000. This is the output that shows the port 10000 is open in the server : # netstat -an | grep 10000 10.70.21.144.10000 10.70.21.133.58130 49640... (6 Replies)
Discussion started by: anaigini45
6 Replies

2. Red Hat

How a service is always running ?

Hi How ssh service at all levels always running in her file /etc/inittab? vi /etc/inittab 10::respawn:/etc/init.d/sshd I added this line & save run init q But it did not (6 Replies)
Discussion started by: mnnn
6 Replies

3. Shell Programming and Scripting

Service checking through shell script

I want to check the postgres service for client PC which is remotely placed through shell script , whether the Postgres service is working or not.I don't have an idea to develop this script.Please give me a code. Client PC IP Address: 10.66.1.133 (2 Replies)
Discussion started by: kannansoft1985
2 Replies

4. Windows & DOS: Issues & Discussions

Running perl script from a VB.NET windows service

Here is the snippet of the code that I'm trying to execute. Stat of the service does not launch perl script. OnStop works fine. Please could you help here. Public Class Service1 Protected Overrides Sub OnStart(ByVal args() As String) ' Add code here to start your service. This... (0 Replies)
Discussion started by: hansini
0 Replies

5. Shell Programming and Scripting

checking to see if a service is running in a shell script

How can I tell, in a shell script, if a certain service is running? I know how to do this on the command line, but not in a script. Is an error thrown somehow that I can check? Thanks. (6 Replies)
Discussion started by: daflore
6 Replies

6. Shell Programming and Scripting

Checking availability of service

HI CAN ANY ONE HELP ME FOR BELOW QUESTION CHECKING AVAILABILITY OF SERVICE IN LINUX (2 Replies)
Discussion started by: satheeshkr_cse
2 Replies

7. Solaris

solaris 8/9 x windows checking

Hi All, I got this solaris 8/9. How do I know if x windows is enabled? I usually access this with console only. I want to know if I can run exceed and gui on solaris at the same time. And how do I know if X11 is what release #? Thank you for any comment you may add. (1 Reply)
Discussion started by: itik
1 Replies

8. Linux

What's better for running Windows software in Linux, Wine or Windows VMware?

What are the differences, advantages, and disadvantages? (1 Reply)
Discussion started by: Advice Pro
1 Replies

9. Windows & DOS: Issues & Discussions

Checking Current Service Pack & Hot Fixes of XP

Dear Sir / Madam, With due respect, I am putting forwarad a question that whenever I am trying to check the current Service Pack & Hotfixes in Windows XP, I am getting the response like as under: (Windows can't find the" qfecheck.exe " check it again) in GUI mode ... (1 Reply)
Discussion started by: swapan
1 Replies

10. Solaris

How to be sure the dns service is running ?

Well, i changed my lan card and finally i got it up and running, i have /etc/resolv.conf with domain xxx.xxx nameserver xxx.xxx.xxx.xxx and it was working with me earlier with the old lan card, with the new one i added it ip using auto-dhcp and its received an ip from my dhcp and it can ping... (4 Replies)
Discussion started by: XP_2600
4 Replies
Login or Register to Ask a Question