VI global search and replace

29 06 2007

In case you need to search and replace text globally within vi, here’s the command to do so:

:1,$s/old/new

vi is a free software screen-oriented text editor computer program written by Bill Joy in 1976 for an early BSD release.

Peace!  \m/



Free Windows PowerShell course book

15 05 2007

The Schweizer IT Professional and TechNet Blog is sharing a free Windows PowerShell course book that they’ve translated to English.  The book seems to be pretty good.

From their blog entry:

 Due to its great popularity, we have decided to translate the Windows PowerShell course book to English. So if your mother tongue is not German, maybe you are interested in the English version instead. The book gives you a short introduction with many exercises about the interactive part of Windows PowerShell as well as some hints how to use other objects like WMI, .NET or COM objects like Excel or Internet Explorer.

The book is available for free and you can share it with all your colleagues or friends if you leave it as it is. The books can be used with or without the demo files available at this blog as well.

Enjoy!  =0)



Accessing specific event logs on a remote server

11 05 2007

An old friend and classmate of mine, Zahid Faisal, wanted to know how to access/read event logs on a remote server using Windows PowerShell. I thought it was an interesting challenge, so after some research and playing around I found that you can make use of the WMI objects to do this.

Follow along to try it out:

1. Open PowerShell and type in the following:

PS C:\> $logs = [System.Diagnostics.EventLog]::GetEventLogs(‘servername’)

This will create a new EventLog object that uses the GetEventLogs method, which by the way, accepts a machine name as an argument. This is exactly what we’re looking for.

2. If the command did not return any errors, continue with the following:

PS C:\> $logs[0]

You should get something like this:

Max(K) Retain OverflowAction     Entries Name

10,240      0 OverwriteAsNeeded      838 Application

The [0] after $logs is simply an array of the different types of event logs, which in this case, [0] equals the Application logs.

3. Next, the bread-and-butter – filtering:

PS C:\> $logs[0].entries | where `

>> {($_.Source -eq “Orion”) -AND ($_.TimeWritten -ge $recent)}

>>

By using the where object, we’re able to filter what we’re specifically looking for. In Zahid’s case, he wanted to grab the most recent logs that are only related to “Orion.”

Take note that this will only work if you’re an administrator on the remote server.

Hope this helps. =0)



Try Ruby online

24 04 2007

Ruby has been getting a lot of praise for a while now, so I decided to give it a try. I was surprised to find so many resources already out there, and one I think worth mentioning is this website.

Ruby is a programming language from Japan (available at ruby-lang.org) which is revolutionizing the web. The beauty of Ruby is found in its balance between simplicity and power.

What’s cool about the Try Ruby! website is that it’s an interactive web-based Ruby shell. And on top of that, it also offers a quick 15-minute tutorial as you go along.

Here’s a screenshot:

Pretty cool, ey? Lastly, here’s an excellent help-and-documentation website, specifically for Ruby if you want to delve and read more on it.

Catch you later. =0)



Put your Mac to sleep via e-mail

14 04 2007

You’re at work, with no remote control access/capability to your Mac at home, brown-outs are occurring, and you forgot to plug it into a power strip due to some unknown reason last night.  What do you do?  Well, read on…

With some preparation, you can take advantage of Apple’s Mail‘s rules feature to run an AppleScript on a filtered message next time.  Here’s how:

  1. Type this script using the Script Editor:
  2. tell application “Finder”

    display dialog “This computer will go to sleep in 1 minute.”  buttons {“Sleep”, “Cancel”} default button 2 giving up after 60

    sleep

    end tell

  3. Save the file somewhere.  I suggest Documents/Scripts (create the folder if it doesn’t exist and start saving all your useful scripts in here).
  4. Open up Apple Mail and navigate to Preferences > Rules > Add Rules.
  5. Copy and setup the following rules based on the screenshot below:
  6. Fig. 1.1 – Apple Mail’s Add Rule window

    Apple Mail rules

  7. Apply the changes and minimize Apple Mail.
  8. That’s it!  All you have to do now is send yourself an e-mail with “Sleep My Mac” as the subject with the message of “Go to sleep” from anywhere.

One caveat: For this to work, Apple Mail will need to be running (minimized is fine). 

Hopefully, you find this tip helpful and empowering.  Now back to work!  =0)