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

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

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.

Hi

Powershell Script:

#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

Are you trying to control a windows system remotely? Look into Windows terminal services.

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