This blog has moved! Redirecting...
You should be automatically redirected. If not, visit http://scrolls.mafgani.net/ and update your bookmarks.

Friday, December 30, 2005

Bash scripting guides

Tuesday, December 27, 2005

Command line search utility

While studying for one of the finals this year, I felt the need for a CLI search utility that would search on Google, Wikipedia, Google Images, etc. I didn't know of any tools that would already do this so I decided to write my own little bash script:


#!/bin/bash
#Needs the htmlview package

opt="$1"
str="$2"


#Create the search string
until [ -z "$3" ]
do
str="$str+$3"
shift
done

case "$opt" in
"google" )
htmlview http://www.google.com/search?hl=en\&q="$str"&btnG=Google+Search &
;;

"image" )
htmlview http://images.google.com/images?q="$str"\&safe=off &
;;

"wpedia" )
htmlview http://en.wikipedia.org/wiki/Special:Search?search="$str" &
;;

"scholar" )
htmlview http://scholar.google.com/scholar?q="$str"\&ie=UTF-8\&oe=UTF-8\&hl=en\&btnG=Search &
;;

"ieee" )
htmlview http://ieeexplore.ieee.org/search/searchresult.jsp?queryText=\%28\%28"$str"\%29\%3Cin\%3Emetadata\%29 &
;;

* )
echo "Usage: search engine searchterm [searchterms]"
echo
echo "Engines: google Basic Google websearch"
echo " image Unfiltered Google image search"
echo " wpedia Wikipedia (English)"
echo " scholar Google Scholar"
echo " ieee IEEE Xplore (needs subscription)"
echo
echo "Example: search image batman"
;;
esac

echo

exit 0



It makes use of the htmlview package to discover the default browser and display the results. The use of the script is quite straightforward:


[darkknight@darkworld bin]$ search image batman begins



As is, it considers all search terms. Fancy things like Boolean expressions are not supported (yet :)). A copy of the script can be found here.

Time synchronization using NTP

I've been having some trouble getting the system clock to sync. with time servers using ntpd. The method that works at the moment is the use of the CLI utility ntpdate:


[darkknight@darkworld ~]$ sudo su -
[root@darkworld ~]# ntpdate time.nist.gov
27 Dec 12:25:17 ntpdate[5743]: adjust time server 192.43.244.18 offset 0.002806 sec
[root@darkworld ~]#



Unfortunately, the man page of ntpdate says that it's set to be removed from the distro. -- hopefully ntpd will work again once that happens.

[Update] It seems the ntpd daemon was missing. The RPM was installed but the daemon was no longer in /usr/sbin/. So, I reinstalled the ntp package and now time sync. works as is should.

Sunday, December 18, 2005

Picture of the Moon

For a while now I've been thinking of photographing the moon. It was a clear night and I finally got around to doing exactly that:



I used my Fujifilm FinePix S5100 (Black&White mode, ISO 200) at a combined maximum zoom of 360x. Then I used Photoshop to increase the contrast a little. I'm quite surprised with the result -- didn't expect this from a consumer grade digicam.