header image
 

Check for a Running Process on a Windows Machine

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 = <<END_OF_MESSAGE
From: #{$from_alias} <#{$from}>
To: #{$to_alias} <#{$to}>
Subject: #{$subject}
#{message}
END_OF_MESSAGE

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

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

#Server list
$proc = ["Server1", "Server2"]

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

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

begin
  File.copy(line.strip, root + templine.strip)
rescue => error
  puts "Error Copying File: Exception: #{error}"
  error
end

Late to a meeting

This is a voicemail which was left on my machine when I was late for a meeting: voicemail

Sending Email via MsSql

Microsoft’s Sql Server always required an odd if not cumbersome configuration in order for emails to be sent by Sql Server itself. An extremely lightweight method of sending emails through mssql is using xp_smtp_sendmail. Xpsmtp adds an extended stored procedure with allows you to easily send emails from Sql Server.

Linux Screen command

I often find myself wanting to make changes to an application while I am also tailing the logs in order to view my changes in action. Up until recently I would start up two separate ssh sessions in order to accomplish this task. Of course I never bothered to think that this may be a common task which many people before me would seek to solve. Luckly I discovered the screen command. The screen command allows you to split your ssh session into various different sessions.

If your machine does not have screen installed, don’t fret….

Debian/Ubuntu

sudo apt-get install screen

Redhat/Fedora

sudo yum install screen

Now that we have screen installed we can run some simple commands which will prove to be valuable:

Start up the screen application:

screen

Split the session into two:

Control+a S

Change over to the second session:

Control+a tab

Start the shell in the second session:

Control+a c

screen application

screen application

You can switch between the sessions by typing:

Control+a tab

You can find additional commands by using the man command or looking up the commands on the internet.

Carlos 2.0

As I mentioned earlier, I am in the process or reorganizing myself for this new year. As part of the Carlos 2.0 project I decided to make Caged Mantis a technology blog where I post some of the fun/challenging things which I have encountered. I have moved all of the old blog posts which were found at Caged Mantis over to my new blog: Amedee Matters. I wanted to separate some of the more personal items over to this new blog. I also finally got around to setting up my personal site at www.amedee.net.

Print Media is Evolving

Newsweek’s N’Gai Croal posted a very interesting link via twitter concerning the state of media. Russ Juskalian of Columbia Journalism Review interviewed Clay Shirky questioning him on a broad range of topics. What I found particularly interesting were his views on the state of print media. The print media commentary begins on the second segment though I think the entire interview is a great read. Part 1 | Part 2