Tuesday, October 20, 2009

Linux power shell commands and tricks: Part I

A lot comes bundled with Linux OS these days (thanks to the FOSS revolution) and we've zillions of utils and UI's to choose from to adapt to the Linux way of life in software development!

Still, Linux encourages the UNIX thought process and the philosophy of DIY (do-it-yourself)...
A power user (developer, build engineer, admin) would programmatically configure (read: automate) his environment and do more with the console using the plain old Linux "shell"

This series (to continue in parts) is on those power shell utilities (command combinations, scripts, performance tuning tweaks) that would help a user do more with less!!!

To start with, here I post a collection of such things that I've found useful:

1) A script (collection of commands taken from Scott Croft's Oracle Tuning on RHEL tweaks) to make your own network-configuration file (using static IPv4 address).

Note:
a) Need root level or sudo access to be able to run this script
b) Tested on RHEL and Fedora.

Takeaway: you'll have a Linux machine configured to communicate over an IPv4 network, with a static IP configuration.

You can copy-paste the below commands in an ASCII text file (with a .sh extension) and create a re-usable script or you can run the commands step by step:

HOSTNAME=$(grep HOSTNAME /etc/sysconfig/network|awk -F= '{print $2}')
hostname $HOSTNAME
GATEWAY=$(ip route list |grep default |awk '{print $3}')
echo "GATEWAY=$GATEWAY" >> /etc/sysconfig/network
DEFDEV=$(ip route list|grep default|awk '{FS=" "; print $5}')
IPADDR=$(ip addr show $DEFDEV |grep inet |grep -v inet6|awk '{print $2}'|awk -F/ '{print $1}')
echo "IPADDR=$IPADDR" >> /etc/sysconfig/network-scripts/ifcfg-$DEFDEV
sed -i 's/dhcp/static/' /etc/sysconfig/network-scripts/ifcfg-$DEFDEV
BCAST=$(ip addr show eth0 |grep inet |grep -v inet6|awk '{print $4}')
echo "BROADCAST=$BCAST" >> /etc/sysconfig/network-scripts/ifcfg-$DEFDEV
echo "NETMASK=255.255.255.0" >> /etc/sysconfig/network-scripts/ifcfg-$DEFDEV

2) Usage of "xargs", "exec" and pipe to do-more-with-less:

a) To add a new extension to all files in a dir:
ls | xargs -t -i mv {} {}.old

xargs reads each item from the ls ouput and executes the mv command.
The -i option tells xargs to replace {} with the name of each item. The -t option instructs xargs to print the command before executing it.

b) To rename a subset of files, specify the file names with the ls command:
ls *.log | xargs -t -i mv {} {}.old

c) To add a current timestamp extension:
ls *.log | xargs -t -i mv {} {}.`date +%F-%H:%M:%S`

The extension will look like ".2009-10-20-19:37:16"

d) To rename just the extension of files:
rename .log .log_archive.`date +%F-%H:%M:%S` *

This command replaces the first occurrence of .log in the name
by .log_archive.`date +%F-%H:%M:%S`

e) Find out exactly which files are eating up a big chunk of your disk space:
To find all files over 10,000KB (10MB+) in size and display their names, along with size,

find / -size +10000k | xargs -i ls -lh {}
or
find / -type f -size +10000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
or, in some other Linux variants:
find / -type f -size +10000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

e.g.
# find /var/ -size +10000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
/var/lib/rpm/Packages: 69M
/var/lib/rpm/Basenames: 11M
/var/lib/rpm/Filedigests: 11M
/var/cache/yum/updates/filelists.xml.gz.sqlite: 57M
/var/cache/yum/updates/primary.xml.gz.sqlite: 21M
/var/cache/yum/fedora/filelists.xml.gz.sqlite: 14M
/var/cache/yum/everything/filelists.xml.gz.sqlite: 59M
/var/cache/yum/everything/primary.xml.gz.sqlite: 29M

...topics coming up next in Part II: memory, process, performance tuning and more!

Tuesday, October 6, 2009

Startup: Inventing Demand, chicken and egg problem

This one talks about business... captures how Steve was able to solve the Chicken n egg dilemma and launch his startup Rentoid that has picked up pretty well and is known as the ebay of Rent.

An interesting read about how Steve invented demand and created such an innovative biz.
Rentoid had a classic chicken and egg problem when it first got launched. People wont list items until we have willing customers waiting to rent their stuff. Conversely, people couldn’t rent things until people willing to rent their items put them up for rent. It’s a bit like asking two people who don’t know each other to fall in love. To solve this problem I decided to ‘Invent Demand’. This is how I did it.

I went out and got myself a copy of the Harvey Norman and all the major department store catalogs. Scan through and them and picked off what items I thought would be suitable to rent. For the purposes of rentoid that meant items that were ‘hot‘ in market (their placement in the catalogue was proof enough of that), items which had a purchase value of over at least $200, and had a low likelyhood of damage. I then proceeded to gather photos of the specific items off Google images and listed each of them on rentoid. The rental prices I placed at 5% of item value for a week, and 10% of item value for a month. The bond I made 50% of the cost. I made sure I listed items from varying categories. I did it in 3 suburbs across Melbourne (North, West & East). The listings also said ‘as new, never used’ – how true. It also assisted with our SEO because people do ‘item & location’ specific searches.
...
When people rented the items, I went out and bought them, first hunting for the lowest price on line. Then rented it to the new rentoid member in good faith and gave them an exceptional user experience.

After the rental I sold the item on ebay for around about 80% of the retail price. I pretty much re-couped my costs doing this.
Seemingly a little deceptive way to catch-the-fish, but is it really? People got what they wanted from the site and the process for both the renter and the rentee was completely transparent.

Customer Focus: Now that it's an established ebay-of-rent... look at what you get from the rentoid team when you email them:
Thanks for your curiosity!
We don't get nearly as many questions as you might imagine at rentoid. We reckon it's because our site is pretty easy to use and hasn't got a million confusing things on every page, or maybe people think we won't answer the query and some computer will.
Sure it's an automated response this time, but a real, living, breathing, person who hasn't nearly had enough sunlight will respond to your question within a day or so. We figure if you cared enough to ask something, we should care enough to respond personally.
If your question is super-urgent give Steve a call on [private number] or Luke on [private number].
Cheers,
The Rentoid team.
Steve figured a brilliant new way to build demand and momentum for his start up. A simple belief worked for him: an action creates a reaction and often people simply liking an idea isn’t enough to give a thumbs-up to a startup.
You got to take that idea forward, do a due diligence, break the rules.... beat the Catch-22 situation, create demand!!!

Friday, September 25, 2009

Cygwin on WinXP/Vista as an X Client

Most of us know cygwin as one of the best/easy Linux-like emulation on WIN/x86 platform. Cygwin also offers a graphical UNIX/LINUX client terminal (unlike putty that's just a character console).
To install/configure cygwin refer Shuva's blog on cygwin.

We can "ssh" to any X machine and open up a full fledged X console (KDE, GNOME etc. for Linux) in 3 steps:

1) From within the cygwin bash terminal, run:
$> x&
$> wmaker&
This will open up the cygwin GUI console that offers many utils as an X Client, including the XTerm.

2) Open Xterm on the wmaker console (right click and select Xterm)

3) On the XTerm command prompt run:
xhost +

4) login to the X host (the UNIX/Linux host to which you want to connect)
e.g.: "ssh username@hostIP"

5) Now that you're logged in to the UNIX/Linux machine, export its Display to your Windows machine IP (where you're running Cygwin) as:
$> export DISPLAY='X.X.X.X:0.0'
where X.X.X.X is your Windows machine IP (the character after : is "zero")

6) Start any X console, like:
$> startkde&
or
$> startX

... and voila!!! You can now see the GUI from your UNIX/LINUX host exported to your Windows client and running within the Cygwin wmaker terminal window. You may even export any other GUI utilities (like web-browser: firefox or email-client: evolution) and run/control them from your WIN client.

All said and done, this is a great, free and easy way to RDP to your UNIX/LINUX GUI console from your WIN box. But, things can go wrong sometimes with Cygwin.
Couple of usually faced issues are described below:

1) When you try to open Xterm window in wmaker (or try any other wmaker util), it doesn't open up and gives an error:
<<<
440 [main] wmaker: 1432 bash: fork_copy: linked dll data/bss pass 0 failed
>0x542000..
>0x5427F0, done 0, windows pid 1960, Win32 error 487
cannot fork a new process: Resource temporarily unavailable
fork failed: resource temporarily unavailable
>>>

Solution:
On your cygwin bash shell:

1) Check if you already have "rebase" package installed (/usr/bin/rebase and /usr/bin/rebaseall)

2) If yes, run the command:
$> /usr/bin/rebaseall
Now, try to open an XTerm window in wmaker and you should be good to go!

Note: Cygwin documents the need for a rebase/rebaseall for some packages/upgrades (like /usr/share/doc/cygwin/python-*.README)

Cygwin FAQ says:
Whether a rebase is required depends on several factors -

1) which packages you've selected (during an install or upgrade)

2) whether those packages have been compiled with --enable-auto-image-base.
The rebase is only required for certain packages, particularly
those that use dynamically loaded modules such as python or perl.

But, the fact is that running "rebaseall" does solve the above issue!

2) Cygwin bash shell (terminal) in WIN Vista doesn't open up fine; won't let you run basic commands; Permission Denied issues!

Solution:
The workaround is to run the Cygwin shell as Admin (before that, activate the real Administrator account)

a) Run Vista command prompt:
cmd

b) execute the following commands:
cd c:/cygwin/bin (or wherever cygwin is installed)
runas /user:Administrator bash

This would start cygwin bash shell with the Administrator account.
To setup the environment for Admin user properly, copy the skeleton files to admin's home folder /home/Administrator/:
execute the following command from the cygwin bash prompt:
. /etc/profile

While Cygwin, being a traditional one out there, works for most of us there are X clients like Xming that provide better GUI's and are compatible w/o tweaks with most WIN verrsions.

Monday, July 6, 2009

World E-Book fair is ON all thru-out this JULY

Folks!
What are we waiting for?
This is it, a collection of ~2 Million titles on nearly all the subjects/topics we know about (..and many that we don't)!!!

There are titles that are difficult to get from the shelf, there are ones that aren't affordable and there are some you'd just like to move your eye-balls thru w/o owning them.

So download/share/read e-books, mobile-books, e-text for your pdf-reader-gadget and
much more.
Visit the World-E-Book Fair, now!