Re: little bit of a nudge with grep, please?

From: Lance Levsen <lance_at_no.spam.please>
Date: Thu Jul 13 2006 - 23:05:58 CST

Dylan Griffiths wrote:
> The good ones to know (IME) are grep, awk (which is nice, because you
> tell awk what to use to split on, and can stick in other formatting
> characters, or even swap orders of columns/words, all in text!), perl,
> sort, and wc. Together, these can do pretty much anything a word
> processor can do, just without the menu part :)
>

I completely agree with your list . . . but I'd add find and sed to that
as well. So maybe it's time to share some of these one-off's that make
life so much easier. Without trying to sound full of hubris, here's two
that I use. The first is a building block for shell math and a watchdog
script, the second is _invaluable_.

1. Counting processes.
$> ps axfw | grep PROD | grep -v grep | wc -l | awk '{print $1}'

The big thing here is sending the results through wc -l which counts
lines. That basically converts a bunch of lines to a number. The awk
just strips out the leading spaces.

2. A cron to notify me and then the user that they haven't removed their
vacation message in a week. This one has proved invaluable in curtailing
the "No one can email me!" phone messages.

$> /usr/bin/find /home/ -name ".vacation.msg" -ctime +7 | /usr/bin/awk
-F/ '{print $3}' > /root/stillonvac.txt; /usr/bin/mail -s "Vacation
longer then a week" root < /root/stillonvac.txt; /bin/sh
/root/bin/vacation_user_notification.sh

The find is the trigger on this one. the -ctime +7 forces find to only
output any .vacation.msg files that are older than 7 days. The awk
parses the results and only prints out the third field where the fields
are split on a /. This is the username in our setup. Obviously this will
break if we use a different mail directory structure.

The vacation_user_notification.sh program just parses the stillonvac.txt
file and mails each user a note.

Cheers,
lance

-- 
Lance Levsen,
Catprint Computing
Tel:  (306) 493-2249
Cell: (306) 230-8783
Blog: http://www.catprint.ca/blog/
SaskBlogs: http://saskblogs.catprint.ca/

Received on Thu Jul 13 23:06:39 2006

This archive was generated by hypermail 2.1.8 : Fri Sep 08 2006 - 23:26:38 CST