Week of bash scripts – rps and commentstrip

These two scripts will respectively: find if a program is running, and strip-comments from text files. The first is useful if you need to see if the program is running or if you need to kill the process with it’s id, comment strip is a good tool to use if posting configurations on forums as often developers or advanced users already know what the settings actually do.

rps

aspire ~/.scripts:
rps geany
todd      1827  0.1  0.3 184576 28616 ?        S    May31   1:05 geany

commentstrip

Commentstrip will display the output to the terminal. If you got xclip installed the ‘c’ option can be used to copy the output to the clipboard.

The final day of week of bash scripts… phew! I’d like to thank everyone that posted comments, and to those that stopped by this week.

About these ads

About Gen2ly

<3's linux

Posted on 2009-08-07, in Linux, Script. Bookmark the permalink. 9 Comments.

  1. Ciaran McCreesh

    What’s wrong with the good old-fashioned ‘ps auxw | grep [d]ns’ ?

  2. lol, I like that too, huh, never seen that before: bracketing the first letter will get rid of the grep result. ah, I guess I’m lazy.

  3. The command line and by extension bash is very powerful in Linux. New users generally freak out about the thought of using them, but they make some very tough tasks a breeze. Thanks for sharing this, I now use this sometimes to look at some files I have that seem to be mostly useless comments (somehow?)

  4. Nice, glad you found a need for it. Yeah, I find the commentstrip pretty useful or but for the not long one I use tail.

  5. Also, what about pgrep? :)

  6. Hold it, I gotta go chase a dog. Yeah, Dan if that what does it for you, lol.

  7. Hi,

    Instead of using
    grep -v “.bin/rps”
    how about
    grep -v “$0″

    This way you can put it anywhere, and bash will remove the name for you.

    Also, you could use #!/bin/sh instead of bash since I don’t see any bash-specific commands in there, and it makes it a touch more portable…

    And finally, copy-and-paste from wordpress seems to put non-breaking spaces instead of normal spaces in the command, so I couldn’t actually run the script until I typed it out by hand!

    cya.

  8. Good tips Iain, thank you. Yeah, I’ve seen $0 used before but doesn’t come to me regularly yet, although now, I think that it will. As for #!/bin/sh I put them in because you know about them but I don’t know enough about bash-specific commands to be able to do so yet. As for the copy-paste thing: it turns out if you use <div style= blah blah> it uses western encoding (or whatever your browser is set to) and not UTF-8. I tested before but the script must have been too basic. Think the problem is mainly with “quotes” but probably other characters in there too. Think the web is just set up this way now mainly, probably for, microsoft systems. Now doing <pre style= blah…> should have it fixed. That’s a big one for me, thanks for the heads up.

  9. Actually I only looked at rps, not commentstrip for sh compatibility. I just found out (man bash) that you can start bash with +B to force strict sh compatibility, which would be useful for testing the portability of your scripts.

    I should have said nice post too :) I like to do things myself too (where I can) rather than use pre-done programs/scripts – I learn better that way.

    cya.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 52 other followers

%d bloggers like this: