Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Wednesday, 11 March 2009

Advanced users don't customize

I was scanning an old post of Joel Spolsky's and found this quote really rung true for me:

"But wait!" you say. "It's important to have options for advanced users who want to tweak their environments!" In reality, it's not as important as you think. ... Most advanced users use several computers regularly; they upgrade their computer every couple of years, they reinstall their operating system every three weeks. It's true that the first time they realized you could completely remap the keyboard in Word, they changed everything around to be more to their liking, but as soon as they upgraded to Windows 95 those settings got lost, and they weren't the same at work, and eventually they just stopped reconfiguring things. I've asked a lot of my "power user" friends about this; hardly any of them do any customization other than the bare minimum necessary to make their system behave reasonably.

It kind of surprised me that it was true, though: I used to be an obsessive preference tweaker but that animal urge seems to have died out along with the desire to immerse myself in video games until 5:00am. I still troll the preference dialogs of any new application, looking for options with as much clout as the Turbo button on old 386 machines, but I can usually close these dialogs without saving.

There are a few customizations I do any time I have a new computer (like deleting useless icons from the Dock or its equivalent). There are even customizations (like setting the refresh rate of the monitor higher than 60Hz so it doesn't hurt my eyes!) I do on every machine I touch. Firefox settings come with me whenever I copy my profile onto a new computer (I want my bookmarks). Other than that, if I can't share the customizations between computers (with an NFS-mounted .bashrc for example), I try to keep them to a minimum.

Of course, with Linux this issue is much less of a problem. I once had a system that I had to expand by putting in a second hard drive. As a result, I ended up with /home on its own drive. The next time I re-installed the operating system I was delighted to find my desktop and all my application settings exactly as I had left them.

Friday, 20 June 2008

Bash: using the read command

While I normally use awk or sed to pull a piece of information I want out of a line of text, it doesn't work as well when you need multiple pieces of information. Well it works fine for displaying multiple pieces of information, but if you want them in variables to use later?

I once wrote a script that used declare to do the equivalent of this:
declare `w | head -1 | 
awk '{ print "DAYS=" $3 " " "USERS=" $6 }'`
# now do something with $DAYS and $USERS

Ewww... Now I know there's a better way: the "read" command. You could do something like this:
w | head -1 |
(read -a FIELDS
#do something with ${FIELDS[2]} and ${FIELDS[5]})

You can also do like so:
ls -l | tail -1 |
(read perms dunno user group \
size month date year file
echo "$user: $file")

You can even loop over all the lines of input. Let's take the /etc/passwd file as an example. Since that file uses a colon as a separator, we first need to set the IFS variable which determines what characters are used as field separators.
cat /etc/passwd | (IFS=:
while read user pass uid gid desc theRest; do
echo "$user: $desc"
done)

As pointed out here, this is also one way to deal with a file containing a list of filenames that may have spaces in them:
cat list | while read f; do
ls -l "$f"
done

Monday, 16 June 2008

Bash: printing the alphabet

(Sorry for the geeky topic, non-geeky readers)

Most have probably run across the "seq" command that will let you generate a list of numbers:
$ seq 1 4
1
2
3
4
But you can do similar with "echo" for a list of letters:

$ echo {a..d}
a b c d
$ echo {a..d}{a..d}
aa ab ac ad ba bb bc bd ca cb cc cd da db dc dd

Friday, 25 April 2008

Asterisk on VMWare

Many people have reported problems with Asterisk running on VMWare and having just decided to play with Asterisk I ran into them myself. First, here's what worked for me (using CentOS 4.6):

  • On the VMWare host machine, edit the .vmx config file for your image and add:
host.noTSC = "TRUE"
ptsc.noTSC = "TRUE"

  • In your CentOS image, disable the cpuspeed process:
chkconfig cpuspeed off

It actually worked fine for me without the extra kernel parameters but the CPU usage seemed to be slightly lower at idle with them added so I left them. The issue seems to be the default clock rate (1000Hz) used by most 2.6 kernels which can't be adequately serviced in the VM guests. The kernel-vm kernel is built with the clock rate at 100Hz.

Apparently CentOS 5 has a new kernel that allows you to specify divider=10 clocksource=acpi_pm to the kernel which tells it to run at 1/10 the clock rate it was compiled with.

Some links:
http://communities.vmware.com/message/762010#762010
http://bugs.centos.org/view.php?id=2189
http://communities.vmware.com/thread/101492?start=0&tstart=0
http://communities.vmware.com/thread/101406