The date command on Unix displays or sets the system date or time. There are a variety of formatting options available.

$ date +"%m"

displays the month(01 to 12)

$ date +"%B"

gives the full month (e.g. January)

See the link for details.

I needed to get the abbreviated last month for one of my scripts. (e.g Nov). It seems that GNU date allows us to use the command as such :

$ date -d"1 month ago"

Sat Dec 1 12:36:42 MST 2007

So, I could get the abbreviated month by saying

$ date -d"1 month ago" +"%b"

It worked fine yesterday. But today(31 Dec) it says that the last month is Dec. When we say “1 month ago” , it tries to look for 31 Nov, and then corrects the date to 1 Dec. That doesn’t work for what I need.

So here is what I did

month=$(date +"%m")
let month=${month}-1
last_month=`date -d"2007-"${month}"-1" +"%b"`

I get the numeric value of the current month and subtract one . In the last step I make a dummy date with the month I calculated and then use “%b” to get the abbreviated last month.

Powered by ScribeFire.


Having fixed the problem with the KVM switch on my machine I proceed to get my Ruby scripts working on Ubuntu. Installing Ruby and getting Rails is a breeze. The problem starts when I need to install ruby-oci8. You cannot get this by doing a gem install….need to download the tar.gz file and run the setup. I try to use tar -xvf ruby-oci8-1.0.0.tar.gz but it fails. (some problem with the header of the file). I then use gzip and tar commands separately and it works.

To install ruby-oci8 you can either do this

make install

or do this

ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

When I try them, both fail. Looking at the error I see that I need to configure ORACLE_HOME (in case of Oracle) or need to configure LD_LIBRARY_PATH (in case of Oracle Instant Client). I know that I don’t have them on my machine so I proceed to get the Oracle Instant Client. I read some blogs (see References) and find that I need the and packages. I download them and unzip them at this location /opt/oracle/instantclient (need to sudo). Having done that I set my LD_LIBRARY_PATH to /opt/oracle/instantclient.


I then proceed to create two symlinks

ln -s
ln -s

Note: In the above case, the names would depend on the version of the instant client that you have.

I go back to try out the ruby-oci8 setup and it fails again. Back to square one and I seem to have run out of ideas. A friend suggests me to check if the instant client works properly by installing sqlplus and connecting to the database. I go ahead with that (I would need sqlplus anyways).
I get the file from here. Unzip it to the location /opt/oracle/instantclient. I now go ahead and set the environment variables through the command line. (I have the LD_LIBRARY_PATH set already) and add my tnsnames.ora file to the same location.

export SQLPATH
export TNS_ADMIN

I try this command at the command line now. (where the username , password and tnsnames have appropriate variables)

sqlplus username/password@tnsname

I get this now:

sqlplus: error while loading shared libraries: cannot open shared object file: No such file or directory

What the !! Now what is this supposed to be?? I read more and run these commands:

ldd sqlplus
strace sqlplus

The first command gives me a list of library dependencies that sqlplus requires and the second command (strace) gives me a trace of system calls and signals. (see man pages of the command for details). Both indicate that a library (libaio) is missing. I run the following command :

sudo apt-get install libaio-dev

Now when I try to run sqlplus I get this error:

SQL*Plus: Release - Production on Fri Dec 21 12:57:36 2007

Copyright (c) 1982, 2007, Oracle. All rights reserved.

ORA-12154: TNS:could not resolve the connect identifier specified

At least I am close. Hmmm…problem with the tnsnames. Soon, I find that I had set TNSADMIN instead of TNS_ADMIN. sqlplus runs once i correct that. So, I can now connect to the database and am sure that the instantclient is installed correctly. Back to ruby-oci8 now.
Running the setup gives me the same problem. This time however I notice that the instantclient is recognized but there is this error (I guess the instantclient was not the problem after all …doh !!)

checking for cc... ---------------------------------------------------
error messages:
Permission denied - mkmf.log

I see that mkmf.log exists in the oci8 dir structure and has root privileges. So, I need to run the setup as root. But since all the environment variables are set on my login the setup complains that it does not see LD_LIBRARY_PATH. I go ahead and add all environment variables to /etc/profile. For global environment variables in Ubuntu see this. I restart my shell and run the following.

sudo -i
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

Success. oci8 now installs without complaints. I try my ruby scripts and everything looks good. The fruit of persistence is definitely sweet.

UPDATES: I was helping a friend install oci8 on his machine when we faced some more hurdles. Adding them here:

1. mkmf not found: You will need the development version of Ruby. sudo apt-get install ruby1.8-dev
2. Make sure you install 32 bit versions and not 64 bit ones.
3. If you see this error : “ cannot open shared object file:”, you are missing the instantclient path. Somehow adding the path in /etc/profile did not get picked up in our case. We had to add it in the .bashrc file. Make sure you open a new terminal after the changes.
4. If you have problems running ruby setup, install etc (see the last step above), check to see if you have the build-essential package installed: sudo apt-get install build-essential


Technorati Tags: , , , , , , , , , , ,

Powered by ScribeFire.

I recently got inspired to try out Ubuntu and being a newbie I wanted to have the best of both worlds (Windows and Linux). The solution was simple; get two systems and use a KVM switch. I found a Belkin KVM in my office for my need and thats where all the mess started.

I connect my systems and nothing responds. Not even XP. I had no manual to begin with (and I didn’t think it necessary to have one; after all its just a KVM switch; thats where I went wrong). After a lot of shots in the dark I finally decide to look for the manual to at least know if I had tried the right hot keys. I google “F1DK102U Manual” and this is the link I get.Well, it doesn’t look like the product that I have…..hmmmm does Belkin have the same model number for the two products? After some searches I get to this link product information on Belkin’s website. Seems like they do support Linux (says in the manual) and they have some kind of installation software for Mac and Windows (none for Ubuntu/ Linux). There is no physical switch on the device and so I don’t have an option. I install the software for Windows and it works fine. Nothing for Linux though. After spending a few hours looking at forums, reading blogs and trying out on my own, I give up. This Belkin switch does not work for Linux even though the manual says so.

I look for other alternative switches and am recommended to try the Trendnet or the Iogear KVM switch. I decide to go for the Iogear. No softwares for this one, but Ubuntu doesn’t work again. A similar switch works for a friend for Ubuntu but not for me. I get the controls for the keyboard and the mouse but not for the LCD monitor(Dell 1907FPt). I try the monitor by connecting to the system that runs Ubuntu directly and the monitor does not work. (it used to before I tried the switches). I look for posts on the Ubuntu forums to see if someone ran through similar problems.

I look at the xorg.conf file in my /etc/X11 folder:

Section "Monitor"
Identifier "DELL 1907FP"
Option "DPMS"

I don’t see the horizontal and vertical frequecy mentioned so I install xresprobe

sudo apt-get install xresprobe

and get the horizontal and vertical frequencies

sudo ddcprobe | grep monitorrange

I make a backup of my xorg.conf file

sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bkup

and change to make the monitor section to look like this

Section "Monitor"
Identifier "DELL 1907FP"
Option "DPMS"
HorizSync 30-81
VertRefresh 56-76

It doesn’t work for me. So, I remove the changes I made to the file. I find a really detailed help page (see here)for fixing video resolutions (not exactly what I am lookng for) that describes a lot of things related to video in general. I try to rebuild my xorg.conf file

sudo dpkg-reconfigure -plow xserver-xorg

I mess up my file and Ubuntu fails to start. I go to safe mode and get a backup of my file, restart and try again with something else. This happens a few times and then I see a section that explains installation of newer drivers. I look at my xorg.conf file and see that the driver that I use is for i810.

Section "Device"
Identifier "Intel Corporation Mobile 915GM/GMS/910GML Express Graphics Controller"
Driver "i810"
BusID "PCI:0:2:0"

Could that be the reason? How can I be sure?
I now use the live CD to get into Ubuntu and look at the xorg.conf file. It mentions the driver as “intel”. Thats all I need. I change the driver to “intel” and restart. Fails again. Now what??
One last try ….I re-install the intel driver.

sudo apt-get install xserver-xorg-video-intel

and change my xorg.conf file once again to Driver “intel”
The driver is installed and the i810 driver is removed. No wonder I had a failure in the last step. Using the KVM switch must have removed the “intel” driver and installed the older ‘i810″ one. Doesn’t Ubuntu keep two drivers for the same device?
Anyways…..I restart and the changes work for me. No problems with resolution no problems with the mouse/ keyboard. I try my Microsoft Ergonomic 4000 keyboard and that works fine too. Nothing better.

Finally, this is what Belkin Customer Support had to say:

We understand that you are not able to install this device on Linux operating system.
As if now we don`t have drivers for this device to install it on Linux computer. We are still under progress and drivers will be released soon. Once the drivers are released it will be posted at :

Technorati Tags: , , , , , , , , , ,

Powered by ScribeFire.

It is no surprise that programmers spend a large portion of their time wading through tons of data. Data and applications go hand in hand after all. It was in one of a recent customer requests that I started looking for certain missing pieces of information in the database and got into the whole data crunching game. It was like looking for a needle in a haystack. (Needles in a haystack would be more appropriate; I never knew how many I was looking for; My manager described it as counting 50,000 cats that kept moving around) The good part of this not so interesting request was that I learnt ways to optimize queries, some new tools and tricks. Getting familiar with Oracle Regular Expressions was one of them.

Oracle regular expression is a new feature in Oracle 10g that gives a lot of flexibility in textual searches. Oracle introduces the REGEXP_LIKE operator and the REGEXP_INSTR, REGEXP_SUBSTR, REGEXP_REPLACE functions which are similar to the LIKE operator and the INSTR, SUBSTR and REPLACE functions respectively.

REGEXP_LIKE: Searches for a expression in the specified column

e.g. SELECT * FROM names WHERE REGEXP_LIKE(first_name,’^(.{5})$’ )

This will return records that have exactly 5 characters (except a newline) in the first name

REGEXP_INSTR: Returns the starting position of a patters

REGEXP_SUBSTR: Extracts a part of the string based on the expression passed to it.

REGEXP_REPLACE: Similar to the REPLACE function except that it takes the expression as the replace string.

POSIX is supported by this implementation which means that we could use expressions like [[:digit:]]{5} or something like [[:upper:]]{4}. The first expression looks for 5 digits and the second looks for 4 uppercase characters.

When to use REGEXP_LIKE and when to use LIKE ?

Most of the articles that I read complained about the slow performance of the regular expressions in Oracle. (compared to the corresponding operator/ functions). The best bet would be to use LIKE / INSTR/ SUBSTR / REPLACE where possible. If things get too complex use REGEXP. Functions like TRANSLATE could give added flexibility too.

Performance or not, it definitely gives you a lot of room for performing quick and dirty searches.

Powered by ScribeFire.

I am numismatist and I had the opportunity of returning to my hobby after a break of a few years. This time I had eBay to help me out to fill in the holes in my collection. I noticed some peculiar patterns in bidding, and the way that the items ended up having a high or a low fetch on the price. I categorized these under ‘sellers’ and ‘buyers’ sections. Each section throws some light on the way we could bid/sell an item. The ideas are very simple but can easily miss our attention when required.

For the sellers:

  • The main aim of the sellers should be to get the bidders compete each other. The final price is not the most important thing. If more than a few buyers get serious about a particular item , it fetches a good price automatically. The buyers see competition and try to bid each other out thus pushing the price higher. Sometimes this leads to a better price than expected.
  • Having the option of PayPal on the bid fetches a far more greater bid on the item. It gives a sense of security and fast payments (obviously at a small cost). I have seen most items go at approximately 50%-60% lower value than the best offers on similar items because they did not carry PayPal as an option.
  • Time duration and the end time of the auction are a very important parameters in getting a good price. I found this to be neglected in most of the auctions. Weekday working hours are a bad time to end the bid. Weekend nights and weekend early mornings are equally bad. Most people don’t want to get up early morning on a Saturday to check whats on eBay.(the only people who do that would be bidders who are desperate to get hold of the item).This is a lose lose situation for the seller. Time zone is the next important thing. 10:00 AM in Eastern would mean 7:00 AM in Pacific. Now you don’t want to lose 1/4 of your potential customers , do you?
  • Never ever give a short description on the item you are selling. One liners on the description are a turn off. The more you describe your item the more confident the buyer is. Don’t ramble on your seller ratings , or your history. (the buyers are smart enough to see that). Instead, spend the space to describe/display the item.
  • Good communication, specially close to the end of an auction, can buy you some points.
  • If you are not sure about how much competition you are going to see for an item, set a reserve or a start price for your bid. Don’t get too ambitious and place a very low price with no reserve. Note: too high a start price/reserve could be discouraging for the bidders

For the buyers:

  • Make sure you search for the item in the title as well as the description.(see the check box below the search text box)
  • Look for the auctions that end at odd times or that have a small life time. (see seller section above for reasons)
  • Search for spelling mistakes in the listings. You can use this search tool. Don’t rely on this too much.(smart sellers are careful when selling)
  • Try bidding on items that have PayPal as a payment option. Money orders and checks take longer time and are not too secure.(you could find less competition on the items without PayPal option though; Power sellers would be a safe option to consider in this case)
  • Many sellers write stories on how they found a collector’s item. Try looking for descriptions on other items that the seller has listed. See similarities?? Its just another trick that the sellers use to make you believe that you are bidding on something really rare and pricey. I read one such description with the seller mentioning that he found a load of old rare coins in an old house that he recently purchased. The description on one of the other items he was selling told about the inheritance he received from his Uncle (bunch of rare nickels). The third one described about a chest of ‘rare’ coins that he found in the auction of a junkyard. What is he??? Sounds like another Tomb Raider movie to me.
  • If a seller is auctioning off an item for someone else, chances are that you might be getting a really good price.(especially if the seller is not aware of the price and if the start price is low). Check the sellers history before you go for the bid. It might be yet another fairy tale.
  • If you are getting a very good item at a very good price with the auction selling off at a price much lower than the market price, LOOK AGAIN. Two happy clicks to be the highest bidder might turn out to be a lifetime regret. For example, search in eBay for “Ballistic Roll coin” (without the quotes and with “search title and description” checked marked) Look through the listings (search for completed auctions if you want more results) and then read the message at this link
  • Be aware of the actual cost and the amount you are willing to pay before you get into the ring. Bidding spree is very common and I have seen bidders pay far more than what the buy it now price offers.

Thats all for now.

Powered by ScribeFire.