As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label moreutils. Show all posts

pee is a C code from moreutils. You can do something with it like:

% pee bc bc
[Press Ctrl+D]

$ echo 1+2 | pee bc bc

pee accepts arguments as commands. It will feed those commands with the standard input it gets.

As usual for moreutils post, I wrote a Bash script, pees:


if (($# == 0)); then
  echo "Please specify command(s) as argument(s) of $(basename "$0")."
  exit 1


while read line; do echo "$line" >> "$TMPFILE"; done

for cmdargs in "$@"; do bash -c "$cmdargs" < "$TMPFILE"; done


Needless to say, pees can do the examples above. But it can also do these as pee can:

ts is a Perl script from moreutils. You use it with pipe, it receives stdout of another program. The basic idea is doing:

command | ts

Its useful when you need to know when a program processes something. But its not enough for me, I wrote a Bash script to do more.


DATECMD='date +%H:%M:%S'

process_stdout() {
  while read line; do
    echo -e "\e[44m$($DATECMD)\e[0m $line"

process_stderr() {
  while read line; do
    echo -e "\e[41m$($DATECMD)\e[0m $line" 1>&2

if (( $# == 0 )); then
  exec 3>&1
  ( bash -c "$*" | process_stdout ) 2>&1 1>&3 | process_stderr
  exec 3>&-

It can timestamp stdout and stderr of a command with different color. See the following example:

The timestamps on red is the stderr of emerge, the rest on blue is the stdout. This script could also be used with pipe, but it would only timestamp on stdin, which is a commands stdout via pipe. Its best to use it like: command arg1 arg2 ...

An example with shell script as command: while true \; do echo tik tok \; sleep 1 \; done

chronic is a Perl script from moreutils collection, runs a command quietly. It eats up the output of the command, but if the command exits with error, which is exit status does not equal to zero, then chronic would show you the output.

From its manpage, it provides a clear example how it could be useful with cron:

0 1 * * * chronic backup # instead of backup >/dev/null 2>&1


I use vixin cron, I dont need to redirect stderr to stdout, just chronic backup >/dev/null would do in the old way.

The old way, using redirection is fine, would not give you message sent to stdout since they are redirected to /dev/null, thought you would see get stderr message from log or email if you have sent up.

chronic would get you both.

I made a simple Bash script,

Cat loves sponge as you can see in this video, but if its soaked with water, a sponge bathing? They would run away next time they see you hiding a sponge behind you. This video provides a nice instructions, if you want to try this one-time only bathing technique:

  1. Acquire cat and remove collar.

    First step is always the hardest, they have sixth sense, they can smell your intentions!

  2. Lightly Soap with dampened cloth (warm diluted solution of cat shampoo is best), ~ praise cat throughout ~

    I doubt they really buy it.

  3. Thoroughly rinse with warm damp cloth, then

  4. Gently towel dry. (do not iron)

    I bet some owners would want to try if ironing is more efficient.

I found its always fun to watch cat getting bathed, though there are some cat breeds do like water. And

Wait a minute!