<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Caged Mantis &#187; Ruby</title>
	<atom:link href="http://www.cagedmantis.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cagedmantis.com</link>
	<description>A systems engineer working on his development skills.</description>
	<lastBuildDate>Sun, 25 Jul 2010 12:40:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Check for a Running Process on a Windows Machine</title>
		<link>http://www.cagedmantis.com/2009/06/10/check-for-a-process-on-a-windows-machine/</link>
		<comments>http://www.cagedmantis.com/2009/06/10/check-for-a-process-on-a-windows-machine/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 19:21:55 +0000</pubDate>
		<dc:creator>Carlos Amedee</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.cagedmantis.com/?p=51</guid>
		<description><![CDATA[This is a quick and dirty method to check for a running process on a windows machine using Ruby. require 'win32ole' require 'net/smtp' require 'yaml' def send_email(message) begin msg = &#60;&#60;END_OF_MESSAGE From: #{$from_alias} &#60;#{$from}&#62; To: #{$to_alias} &#60;#{$to}&#62; Subject: #{$subject} #{message} END_OF_MESSAGE Net::SMTP.start('smtp.company.com') do &#124;smtp&#124; smtp.send_message msg, $from, $to end rescue =&#62; error puts &#34;Exception: #{error}&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick and dirty method to check for a running process on a windows machine using Ruby.</p>
<pre class="brush: ruby;">
require 'win32ole'
require 'net/smtp'
require 'yaml'

def send_email(message)
  begin
    msg = &lt;&lt;END_OF_MESSAGE
From: #{$from_alias} &lt;#{$from}&gt;
To: #{$to_alias} &lt;#{$to}&gt;
Subject: #{$subject}
#{message}
END_OF_MESSAGE

    Net::SMTP.start('smtp.company.com') do |smtp|
      smtp.send_message msg, $from, $to
    end
  rescue =&gt; error
    puts &quot;Exception: #{error}&quot;
  end
end

$from_alias = &quot;Email Alias&quot;
$from = &quot;processWatcher@company.com&quot;
$subject = &quot;Process Error&quot;
$to_alias = &quot;Email Alias&quot;
$to = &quot;alerts@company.com&quot;

#Server list
$proc = [&quot;Server1&quot;, &quot;Server2&quot;]

$proc.each { |record|
  runningProc = false
  begin
    wmi = WIN32OLE.connect(&quot;winmgmts://#{record}&quot;)
    processes = wmi.ExecQuery(&quot;select * from win32_process&quot;)
  rescue =&gt; error
    puts &quot;Exception: #{error}&quot;
  end
  for process in processes do
    if (process.Name == &quot;SampleProcess.exe&quot;)
      puts &quot;Server: #{record} Name: #{process.Name}&quot;
      runningProc = true
    end
  end

  if runningProc
    puts &quot;Process on #{record} not running as of #{Time.now}. Please check the server.&quot;
    send_email(&quot;Process on #{record} not running as of #{Time.now}. Please check the server.&quot;)
  end
}

begin
  File.copy(line.strip, root + templine.strip)
rescue =&gt; error
  puts &quot;Error Copying File: Exception: #{error}&quot;
  error
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cagedmantis.com/2009/06/10/check-for-a-process-on-a-windows-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
