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!!!