The Awakeness of Shell Scripting with AWK

I guess I’m getting too used to the “it’s been a while!” thingy so, awkward title aside, let’s just move straight to today’s post:

The more I learn about AWK, the more I love it. It’s just that simple. I’ve been trying its powers a bit and came with an awk-mazing (and probably useless, but still exciting) five-lines (sans comments) cute script that emulates the most popular feature (the “-e” option) of our good ol’ boy apropos.
Enter lazyman!

#!/bin/bash

# lazyman.sh - displays the name section of a program’s man page.

# DESCRIPTION
# this tiny script shows the NAME section of a given program’s
# manual page, displaying an output quite similar to “apropos -e”
# but directly calling “man” instead of querying against “mandb”.

params=$(echo $@ | awk ‘END{print NF}’)

case $params in
1) man $1 | awk ‘/NAME/{getline;print}’ ;;
*) echo “usage: lazyman.sh [program]” ;;
esac

That’s all folks! I hope you’ve enjoyed it and thanks for reading!

UNIX Programming: Simple Notifications With mailx

Hey there! I know it’s been a month since my last post, I’m sorry about that but I’ve been pretty busy this days, having a lot to do at work and also being a full time student, so anyway, this time I’m sharing with you a nifty tip regarding notifications using mailx on UNIX, so without further ado, here’s the actual code:

#!/bin/ksh

#mailx settings
to=”someone@somewhere.com
subject=”[Notification] Something happened
body=“Lorem ipsum dolor sit amet et cétera

#run and notify
runSomething && (echo $body | mailx -s “$subject” “$to”)

I hope you find it interesting, thanks much for reading and don’t hesitate to leave a comment!

Checking For Duplicated Processes In Korn Shell

A couple of days ago I was needing to solve an issue with our EAI framework. The implementation of such framework could be basically described as instances of Java programs running under Solaris, but there’s a particular instance that should be running just once. So I wrote this tiny shell script to avoid launching that program twice:

#!/bin/ksh

theProcess=someProcess

if [ $(pgrep -u $USER -f $theProcess | wc -l) -gt 0 ]
then echo “There is an instance of “$theProcess” already running.”
else runTheProcess
fi

someProcess could be any regex that matches the process description,
runTheProcess is whatever command that executes the process.
Okay, that’s all, I hope you’ve found it informative and thanks for reading!

Chances, Changes, Challenges.

Hello world! Well basically I’m shifting the course of my beloved little blog from just quoting slash reposting or, in a more trendy web 2.0ish lingo, “consuming syndicated content”, to actually authoring my own stuff, that is, in principle, publishing any tip, trick, hack and what have you I happen to consider my audience would be interested in reading (that audience being just my close friends at the moment). Anyway, so without further ado, let’s make it happen! And as a footnote, please be nice with what I like to call “my developing creative writing talent”, I’m no language major, actually I’m not even a native English speaker, but I will do my best to write it all pretty for you guys :)

Next Page »