Linux, programming, computers and life

July 22, 2008

searching your organization address book from command line

Filed under: CLI, programming

Let’s assume that you are working in a relatively small organization, 4-5 hundreds people at most. I’m sure you have some kind of intranet and there’s a phone book there. I’m pretty sure you have a page with most used phone numbers pinned on your wall somewhere.
Here’s idea how to search those phones from command line. The solution is based on two scripts. First downloads the names list and formats it as necessary (mine strips all HTML mumbo-jumbo). This one is called periodically by cron. Second is used for names list search.

Here are the scripts:
update_tel_db
#! /bin/sh

cd /your/path/to/database
wget http://your.path.here/file.here >& /dev/null
touch tel.txt ; \rm tel.txt
links -dump file.here | grep @ | grep -v — ——————– | grep -v mailto | grep -vi ‘Click here’ | grep -v javascript | grep -v IMG | grep -v file: | tr ‘|’ ‘ ‘ | sed ’s/^ *//’ | sed ’s/ / /g’ | sed ’s/\[[0-9]*\]//g’ > tel.txt
\rm file.here >& /dev/null
touch tel.txt

tel
#! /bin/bash

echo ‘NAME DPT OFFICE CELL-PHONE HOME E-mail’
grep -i $1 /tour/path/here/tel.txt

Now telephone search becomes tel name on the command line.
Enjoy :)

July 20, 2008

adding command output to each line of file

Filed under: CLI, programming, awk

I wrote about changing of certain columns in a file, but here let’s solve a simpler task. I’d like to add something, let’s say date, to every line of a file. I’ll emulate a file using `seq 1 10`.

The following is easy enough:
seq 1 10 | awk '{print "echo `date` "$0}' | bash

However, there’s simpler solution:
seq 1 10 | while read ; do echo `date` ${REPLY} ; done

It works because REPLY variable is set to the line of input read by the read builtin command when no arguments are supplied (from bash manpage).

May 9, 2008

Filed under: life

Ipod shuffle is nice because:

  • it’s cute
  • it has good sound quality
  • it’s CUTE (according to my girlfriend)
  • opening experience is really great
And NOT nice because:

  • iTunes
  • one must do something besides copying the files to the device
  • iTunes (according to my girlfriend)
We both fought ITunes (and we both have degrees in computer science and both programmers), for me it was a second time, and we lost. Finally, when we understood what to do, in order to get our audio collection transferred to shuffle not randomly, we had to import the collection to iTunes. Which was taking ages… (nice touch - format conversion is asynchronous to other operations with iTunes).
So i uninstalled the damn thing, together with quicktime player (hehe). And using simple iPod Shuffle Without iTunes (which only takes several kilobytes and evel looks mac-like) we finally won.
Or, from other point of view, lost to iTunes ;) .

April 22, 2008

assumption is…

Filed under: life

There’s a nice quote i remember from “Under Siege 2:Dark Territory” movie.

“Assumption is the mother of all fuckups”
It’s very true in programming by the way.
A good friend just wrote email to me saying:
Not googling is also mother of all f#@k%#s :)

Technorati Tags: ,

March 3, 2008

parallel execution in bash scripts

Filed under: CLI, programming, linux

Recently, i had a problem - i needed to run several utilities in parallel in bash script, wait till they finish and then gather the information they produced. It’s sooooooooo easy!
Bash has ‘wait’ command which… (surprisingly) waits for all (or certain) background processes to finish. Knowing that, the rest is easy.
Here’s a bash script which simulates utilities with ’sleep’ command.
nParallelTasks=10
nStartedTasks=0
for i in `seq 1 100`
do
echo "-- $i --"
sleep 5&
nStartedTasks=$(($nStartedTasks + 1))
if [[ "$nStartedTasks" == "$nParallelTasks" ]]
then
echo "waiting"
wait
nStartedTasks=0
fi
done

Technorati Tags: , , , , ,

February 26, 2008

creating panoramas - Autostitch™

Filed under: life

I think i found the best way to create panoramas - Autostitch™. It’s easy, free and simply works. Here’s Bansko panorama created with it. And it’s possible to run it with WINE ;) .

Technorati Tags: , ,

February 17, 2008

one citation from bash.org.ru

Filed under: internet, linux

bash.org.ru is bash.org in russian :) . Here’s one citation i felt i must translate (original in russian):

<@insomnia> u have to execute three commands to install Gentoo
<@insomnia> cfdisk /dev/hda && mkfs.xfs /dev/hda1 && mount /dev/hda1 /mnt/gentoo/ && chroot /mnt/gentoo/ && env-update && . /etc/profile && emerge sync && cd /usr/portage && scripts/bootsrap.sh && emerge system && emerge vim && vi /etc/fstab && emerge gentoo-dev-sources && cd /usr/src/linux && make menuconfig && make install modules_install && emerge gnome mozilla-firefox openoffice && emerge grub && cp /boot/grub/grub.conf.sample /boot/grub/grub.conf && vi /boot/grub/grub.conf && grub && init 6
<@insomnia> that’s first.

Technorati Tags: , , , ,

February 14, 2008

awk + bash = power

Filed under: CLI, programming, awk

I wanted to call this “advanced awk”, but it’s in fact simple idea with awk and bash integration. I got this idea from wonderful ArchLinux forums.
The problem is as follows. Given a file with several columns, i want to run a command on some columns and keep other columns as is.
For example, given a file with user names and some more information, i need to convert user names to user ids and keep other information unchanged. Example file is:

root a b c
ftp   d e f

The desired result is:
0   a b c
14 d e f
(of course, user id of ‘root’ is 0 and of ‘ftp’- 14)
Well, there’s a way to do this :) . First we’ll convert the file using awk or sed to ‘echo’ commands and then use bash to interpret those.Take a look at the output of the following command:
cat myFile | awk '{print "echo \"$(id -u "$1") " $2 " " $3"\""}'
And now, only thing left to do is to execute the commands awk created for us - i.e. pipe to bash ;)
The final command is:
cat myFile | awk '{print "echo \"$(id -u "$1") " $2 " " $3"\""}' | bash

Enjoy!

Technorati Tags: , , , ,

February 11, 2008

flash sites

Filed under: internet

A long time ago i wrote about how much i hate flash sites. I still do. The situation is even worst now. There are some sites with demand that i upgrade my flash player. I am not always able to do so. I almost never want to. If you create a flash-only site, u should at least provide some text information when flash player is not available.  Let me correct myself, do not create such sites!.
Here’s how a site of a modumobile looks (which is supposed to be cooooool startup). How can i trust such a company, if it cannot even create a normal website?

modumobile site on my comp

Technorati Tags: , , ,

January 23, 2008

psi emoticons theme from pidgin

Filed under: internet, linux

Not long ago i wrote about smiley theme for psi i created from pidgin’s theme. I’ve put the file on rapidshare in order to easily count the downloads. I got 4, one of them was myself :) . I got no feedbacks so far.. is it that good or that bad?
BTW, Arch Linux changed it’s logo, it’s on the right side of this blog somewhere.

Technorati Tags: , , , ,

Get free blog up and running in minutes with Blogsome
Theme designed by Gary Rogers