domingo, 3 de abril de 2011

Query WikiPedia via console/shell script

Sometimes we need an quick answer about something...yeahh! We have google :-). But if we are working without graphic environment or if we need an quickly quickly answer?

We can make an query from command line to wikipedia and we got the response instantly, without advertisements, without open pages in web browser and without search in web page from the answer that we need.

So I developed an shell script to do this job for us:
#!/bin/bash
# Developed by Antonio Mendes 3/04/2011
#
# about - this script returns a few documentation about something
#

QUERY_STR=$@

TEST_NET=$(ping -c 1 www.wikipedia.org  2> /dev/null | grep "0% packet loss")

if [ "$TEST_NET" != "" ]; then
        ANSWER=$(dig +short txt "$QUERY_STR".wp.dg.cx)
else
        echo "Network down, please try again later!"
        exit 1
fi

if [ "$ANSWER" != "" ];then
        echo $ANSWER
else
        echo "Your query don't return any result, please make sure that it's a valid term!"
fi
Next save as about and give execution permissions.

To execute you must call the script wiht the word to query like this:
 antonio@pc:~$ ./about Benfica
"Sport Lisboa e Benfica (\; commonly referred to as simply Benfica, S.L. Benfica and in many fan anthems as SLB ) is a multisports club based in Lisbon, Portugal, best known for its football team. Sport Lisboa e Benfica was founded in 1904 by a group of twe" "nty-four men. The club's main stadium is the Est\195\161dio da Luz in the Luz area of Lisbon... http://a.vu/w:S.L._Benfica"
 antonio@pc:~$ ./about Linux
"Linux (commonly pronounced in English\; variants exist) is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration\; t" "ypically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the... http://a.vu/w:Linux"
It's all, from now on you have an Wikipedia in your command line.

sábado, 2 de abril de 2011

Linux kernel 2.6.39 RC is available

Just launched the first version 2.6.39 RC of Linux kernel.
Some features: 
Nouveau drivers for Nvidia cards will give a boost of outstanding quality, Exceeding even the proprietary driver performance . More or less the same thing happened and the Ati in the Kernel 2.6.38, yielding 3D quite well but as a user of a HD series 400.

For list of completed new features/changes go to official website.

Log in Linux with an USB Pen Drive

Recently I had the idea in increase the security of my Netbook, so I think if it's possible to keep an user session only if an determinated USB pen drive is plugged. I have made an research and I found that there are already some tools to do that.
One of the most popular is pam_usb tools, this tool provides, among other things to do:
  • Password less authentication, use USB stick for that;
  • Two-factor authentication. USB stick and password to authenticate the user.
  • Support for all kind of removable devices (SD, MMC, etc);
  • It works with any application supporting PAM, such as su, any login manager (GDM, KDM), etc.
 How to install:
 First install needed packages:
apt-get install libpam-usb pamusb-tools
Connect the pen drive and add it to any name.
Note: Check if it's only one pen drive connected;
Note2: The data in pen drive is not erased.
pamusb-conf –add-device token

Now add the user account associated to that pen drive.
pamusb-conf –add-user youruser
Note: Answer all questions with 'yes'.

Check if all process is done correctly: 
pamusb-check youruser
If it says: Access Granted it's all ok.

Finally you must add " auth sufficient pam_usb.so" to file /etc/pam.d/common-auth.

From now you can login with your USB pen drive, but it's not all you can run an script and perform some action...For more information please visit the official page.