Thursday, November 17, 2011

Killgrep - Kill a process by part of its name

We know the command kill that can kill a process by its id, and we know killall that can stop the processes by its full name. What if we need to kill a process by some part of its name and/or arguments. A simple killgrep script can do and here is how it is done:


#!/bin/sh

# killgrep: Usage: killgrep server.py 
# will kill the process running like "python server.py"

echo $1

if [ -z "$1" ]; then
 echo "killgrep: "
 exit 1
fi

PROC=`ps auxwww | grep "$1" | grep -v grep | wc -l`
if [ $PROC = "0" ]; then
 echo "killgrep: None killed"
 exit 1
fi

PROC=`ps auxwww | grep "$1" | grep -v grep | perl -e '$_=<>; @u = split; print $u[1]' -`
if [ ! -z $PROC ]; then
 echo "killgrep: Stopping process $PROC"
 kill $PROC
fi

Saturday, November 12, 2011

How to add a custom launcher in Ubuntu Unity Panels? (11.04+)

Prior to Ubuntu 11.04 (Natty Narhwal), you had Gnome Panel and it was easy to add a new custom launcher or an application to your Panel. But with Natty, by default, Ubuntu has the Unity interface which is very different from the classic Gnome Panel.

Now, you can easily create a "shortcut" on the Unity sidebar by opening the list of applications and then dragging a particular app onto the sidebar. But there is no obvious way to create a custom launcher - an application you have installed manually or a script that you have written, and get it placed on the sidebar. In my case, it was Thunderbird 8 which I just downloaded and placed it in /usr/local/thunderbird and I need to launch that instead of the regular packaged thunderbird.

Here is a simple method of how you can accomplish that:


  1. Right click on the Desktop. Click on "Create Launcher"
  2. Provide the name and path of the Launcher application and click OK to create the Launcher.
  3. Then just drag that launcher from the desktop to the sidebar panel! That's it!