Have you ever wanted to add a leading timestamp on each line of a given output?
That would make it a perfect professional syslog-like log!
Fortunately, it’s just a one-liner with gawk (the gnu version of the popular tool):
$ ./command | gawk '{print strftime("%b %d %T",systime()),$0;}'
For example, you can create a simple one-on-one IRC-like connection with:
$ nc -l -p 1234 | gawk '{print strftime("%b %d %T",systime()),$0;}'
set 16 18:25:27 Hi!
set 16 18:25:31 Are you there?
yes
set 16 18:25:41 Great!
The user you want to chat with, will have to run
Here is an incomplete and badly sorted list of the most useful combinations of apt/dpkg I have been using lately.
Please remember that those command lines which start with a # need root pemissions.
Let’s suppose we have a number expressed in given base (i.e. “E0″ in hexadecimal). How can we convert it to decimal using bash or other common Unix tools? And what if we need to perform an any-to-any base conversion?
First way: printf + hexdump
We can tell bash that a given string is just a disguised hexadecimal number by adding “\x” at the top of it and then using the built-in printf function to recover the number:
$ foo="6F"
$foo2="\x"$foo
$ printf "%b" $foo2 | hexdump -e '1/1 "%d" "\n"'
111
$ printf "%b" $foo2 | hexdump -e '1/1 "%o" "\n"'
157
Please notice that %d makes hexdumo to return a signed integer; if you need an unsigned integer just replace it with %u:
Sometimes you need to get mplayer/mencoder inside a script. Let’s say you want to automatically grab a picture from your webcam every 10 seconds:
capture_w=here goes the capture width of your webcam
capture_h=and here the height
mplayer -slave -quiet -input file=/tmp/tmp.fifo \
-vf screenshot,eq2,scale=500:375 \
-tv driver=v4l:quality=90:height=$capture_h:width=$capture_w:input=0:norm=pal:\
noaudio:contrast=10:brightness=-25:saturation=100 tv:// \
-vo null &>/dev/null&
while :; do
echo "screenshot 0" >/tmp/tmp.fifo
sleep 10;
done
(parameters of the tv option may vary for your webcam)
or encode the last grabbed frames of the webcam in a video: