tail -f findings.out

ack: grep but better!

I came across ack today, and now grep is sleeping outside. It’s very much like grep, except it assumes all the little things that you always wanted grep to remember, but that it never did. It actually left the light on for you, and put the toilet seat down.

Anyway, there were some rough bits with installation. On Ubuntu, it is installed by

1
sudo apt-get install ack-grep

If you think, hey, I will take the obvious path and install “ack”! You will be thinking with wrongitude. For

1
ack

is, in fact, a Kanji code converter, which I discovered after not a little anger. On RHEL, CentOS, and the like, you have to install with

1
cpan -i App::Ack

Once installed, just try some

1
ack-grep STRING

Want to ignore .svn dirs? It already did. Want to recursively search? It already did. And it brought over a bag of chips. Read the Top 10 for more goodies.

Oh, and don’t forget to add

1
ack-grep --thpppt

to exit your shell scripts:

Tags: , ,
September 22, 2008 - 1:57 PM Comments (7)

Needs more cow…say!

I stumbled across a wonderful program today: cowsay! It is just as cool as you would imagine:

1
cowsay "Text"

gives you an ASCII art cow saying your Text.

I think I will use it as the welcome banner on all my servers:

Tags: , , ,
July 16, 2008 - 11:58 AM No Comments

Handy Network Utilities: nast, fping

I discovered a wonderful utility last night: nast. I wanted to scan my local network, just to see what devices were on it, what their addresses were, etc. I could ping my entire subnet, but what if I had a machine that rejected ICMP packets? (Not that I do very often, but it can happen in larger environments). I thought using a protocol like ARP would be much more robust, since it is pretty much guaranteed to be available. Then I discovered nast.

nast can do a lot of neat things. The first I found was mapping a subnet of course, which you can do by running

1
sudo nast -i eth1 -m

This returns something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Nast V. 0.2.0

Mapping the Lan for 255.255.255.0 subnet ... please wait

MAC address     Ip address (hostname)
===========================================================
00:1A:4D:9C:6D:30   192.168.1.5 (B74kB0x.home) (*)
00:18:01:2E:5F:66   192.168.1.1 (Wireless_Broadband_Router.home)
00:04:4B:03:2F:0D   192.168.1.2 (MediaServer.home)
00:21:5A:35:E0:43   192.168.1.3 (new-host.home)

(*) This is localhost

Finished

nast can also try to find out if there are any nodes on your subnet acting in promiscuous mode, which I think is pretty hot. Check out the main nast page for the full feature set.

In my searching, I also came across fping. Its main improvements over regular old ping are:

  • More than one host can be passed (as well as a file containing hosts)
  • Output is very simple and easy to parse, making it ideal for scripting
  • Tries each host and moves on if there is no response, making the whole process faster

Instead of

1
ping -c 1 myhost1 ; ping -c 1 myhost2

you can just run

1
fping myhost1 myhost2

which just returns

1
myhost1 is alivemyhost2 is alive

Both nast and fping are available in the Ubuntu repos.

Tags: , , ,
July 10, 2008 - 10:57 AM No Comments

Reference script for CLI color codes

I have been experimenting with adding more color to my bash prompts of late. I find it easier to read when the fields are in distinct colors. The problem I always have is remembering what those wonderfully obscure ANSI escape sequences represent. I always have to look at a table to remind myself that “light red” maps to “1;31″.

In an interesting guide to configuring your bash prompt that I have been going through, there was a script listed that makes this much easier:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
#
#   This file echoes a bunch of color codes to the
#   terminal to demonstrate what is available.  Each
#   line is the color code of one forground color,
#   out of 17 (default + 16 escapes), followed by a
#   test use of that color on all nine background
#   colors (default + 8 escapes).
#
# Taken from the Bash Prompt HOWTO:
# http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html

T='gYw'   # The test text

echo -e "\n                 40m     41m     42m     43m\
    44m     45m     46m     47m"
;

for FGs in '    m' '   1m' '  30m' '1;30m' '  31m' '1;31m' '  32m' \
           '1;32m' '  33m' '1;33m' '  34m' '1;34m' '  35m' '1;35m' \
           '  36m' '1;36m' '  37m' '1;37m';
  do FG=${FGs// /}
  echo -en " $FGs \033[$FG  $T  "
  for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
    do echo -en "$EINS \033[$FG\033[$BG  $T  \033[0m";
  done
  echo;
done

This is from the Bash Prompt HOWTO, from a script by Daniel Crisman. It produces the following when run:

Just add an alias like

1
alias colors="~/dir/of/handy/scripts/print_shell_colors.sh"

, and you can be reminded whenever you like.

I am still experimenting with my prompt colors, but differentiating the fields I find useful has made things a lot easier:

Tags: , ,
October 31, 2007 - 2:08 PM Comment (1)

View compressed log files easily

Any linux distribution around these days will have compression and rotation in place for files in

1
/var/log

(or wherever else they happen to go). So if you look in there, you will see one or two log files (current and the last one) for each process logged, as well as 3-7 compressed files for the same process. These then get rotated out.

In any case, say you want to look inside one of those compressed log files. You could write out an untar command and then view the file. Then have to delete the temporary file. Messy. There is a better way.

The first I found was interesting (from PuppyLinux): Simply run

1
man ./COMPRESSEDFILE

. You view the contents of the file with the man file viewer. The annoying thing is that is does funny things with line breaks.

A much better way:

1
<a href="http://www.mkssoftware.com/docs/man1/zcat.1.asp">zcat</a> COMPRESSEDFILE | less

. You view the file in less, and when done, there is no temp file to delete. To make it faster, just add a simple alias:

1
alias viewlog="zcat $1 | less"

. This makes viewing those compressed logfiles as painless as viewing the current ones.

Tags: , , ,
October 30, 2007 - 3:20 PM Comments (2)

« Older Entries

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.