Junk Food for the Brain

Open Source and Awesomesauce :)

Vim How to Show Line Numbers

| Comments

Sometimes when editing configuration files or for quick debugging on a server, you use vim. And you wish it could show line numbers.

Actually it can. Here’s how:

In command mode, type

set number

.

Yup, that’s it.

RPM Fusion for Fedora 15

| Comments

At the time of writing, RPM Fusion still has not published a link to the stable repo for Fedora 15. You may have installed the stable RPMs and got an error like this:

[Errno 14] Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmfusion-nonfree-fedora-15-arch

The workaround for now is to disable the GPG check.

Install as usual:

su -c 'yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm'

In your

/etc/yum.repos.d/

, you should disable the gpgcheck option.

e.g. In your

/etc/yum/repos.d/rpmfusion-nonfree.repo

file, set

gpgcheck=0


[rpmfusion-nonfree]
name=RPM Fusion for Fedora $releasever - Nonfree
#baseurl=http://download1.rpmfusion.org/nonfree/fedora/releases/$releasever/Everything/$basearch/os/
mirrorlist=http://mirrors.rpmfusion.org/mirrorlist?repo=nonfree-fedora-$releasever&arch;=$basearch
enabled=0
metadata_expire=7d
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmfusion-nonfree-fedora-$releasever-$basearch

Or, you could download the gpg keys as stated in this post: NoteIts in Spanish.

Fedora 14 Logitech EX-100 Numpad Not Working

| Comments

Took me awhile to get to figuring out this one out.

You may realise that your numeric keypad doesn’t work after a new install. When you use the 4,6,8 & 2 keys, it may be moving the mouse cursor instead.

To fix that:

System -> Preferences -> Keyboard

That should open a Keyboard Preferences window.

Choose “Mouse Keys” and uncheck Pointer can be controlled using the keypad.

That will give you back you numpad.

Generate Files With Random Content and Size in Bash

| Comments

Occasionally you need to generate a bunch of random files with random content, usually for testing compression, user quotas or miscellaneous stuff.

Here’s one way, using the bash shell and a few handy linux utilities.

  1. The bash $RANDOM function. It generates a random number between 0 - 32767.
  2. Linux DD utility, to output files.
  3. /dev/(h|s)da, your hard drive in linux.
  4. All wrapped in a bash while loop.

So lets start. First define a bash variable with the number of files we wish to create, lets say 10.

no_of_files=10

Then we’ll assign the a bash variable for the counter.

counter=1

As for the dd command, this creates a file with random content from your hard disk. (Mine’s /dev/sda) which is 1KB in size. The count switch tells dd to repeat 1024 bytes 1 time, thus the 1Kb file size. skip makes dd skip an x amount of bytes before reading further. Since this requires raw access to your hard drive, you’ll have to run this as root unfortunately. :(

dd bs=1024 count=1 skip=0 if=/dev/sda of=random-file

So now imagine, if we let bash assign the count and skip random numbers, we get random file contents. (Light bulbs flashing eh?)

Of course, all of it will be written to a single file called random-file in my case. To add just slight amount of variety, we can add the counter variable that we will use in our while loop as an extension. The dd command will now be:-

 dd bs=1024 count=$($RANDOM) skip=$($RANDOM) if=/dev/sda of=random-file.$counter

Finally, we will wrap it up in a bash while loop like this:-

no_of_files=10;
counter=1; 
while [[ $counter -le $no_of_files ]]; 
 do echo Creating file no $counter;
  dd bs=1024 count=$RANDOM skip=$RANDOM if=/dev/sda of=random-file.$counter;
  let "counter += 1";
 done

When you run it, you will get output like this:-

Creating file no 1
16614+0 records in
16614+0 records out
17012736 bytes (17 MB) copied, 0.29308 s, 58.0 MB/s
Creating file no 2
14456+0 records in
14456+0 records out
14802944 bytes (15 MB) copied, 0.100101 s, 148 MB/s
.................
Creating file no 10
25224+0 records in
25224+0 records out
25829376 bytes (26 MB) copied, 0.492113 s, 52.5 MB/s

when you do a directory listing, you’ll see this:-

[root@atreides rd-test]# ls -lh
total 226M
-rw-r--r-- 1 root root 17M 2009-07-29 00:25 random-file.1
-rw-r--r-- 1 root root 25M 2009-07-29 00:25 random-file.10
-rw-r--r-- 1 root root 15M 2009-07-29 00:25 random-file.2
-rw-r--r-- 1 root root 20M 2009-07-29 00:25 random-file.3
-rw-r--r-- 1 root root 21M 2009-07-29 00:25 random-file.4
-rw-r--r-- 1 root root 30M 2009-07-29 00:25 random-file.5
-rw-r--r-- 1 root root 22M 2009-07-29 00:25 random-file.6
-rw-r--r-- 1 root root 27M 2009-07-29 00:25 random-file.7
-rw-r--r-- 1 root root 25M 2009-07-29 00:25 random-file.8
-rw-r--r-- 1 root root 29M 2009-07-29 00:25 random-file.9

For more info, refer to the $RANDOM function from the Advanced Bash Scripting Guide.

How to Enable Flash in Google Chrome for Fedora 11 I686

| Comments

So you’ve installed the latest development builds of Chromium for Fedora Linux. The only thing lacking is that youtube is not loading. If not, what are you waiting for? Refer to one of my previous posts.

First make sure you install the Adobe yum repository.

As root:-

rpm -ivh http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm

Then install the flash plugin.

yum install flash-plugin.i386

The flash plugin will be installed in /usr/lib/flash- plugin/libflashplayer.so

Chrome plugins are supposed to be located in /usr/lib/chromium- browser/plugins. So lets create a symbolic link, so that whenever your Adobe flash plugin is updated, your Chrome automatically gets the latest version.

n -sv /usr/lib/mozilla/plugins/libflashplayer.so /usr/lib/chromium-browser/plugins/libflashplayer.so

Now start your Chrome browser from the command line, with the --enable- plugins switch. This will enable the flash plugin.

Here’s a screenshot of me watching a video from youtube on chrome:- [caption id=”attachment_241” align=”aligncenter” width=”300” caption=”Flash Player in Google Chrome for Linux”]Flash Player in Google Chrome for
Linux[/caption]

Say goodbye to geek productivity once this is done :D

Temporarily Disable a Yum Repository

| Comments

Sometimes, you may run into problems updating Fedora via yum. What you could do is temporarily disable the offending repository, and update everything else while the errors are being fixed upstream.

  1. List out your enabled yum repositories.
$ yum repolist

You would get something like this:

[raja@atreides ~]$ yum repolist
Loaded plugins: fastestmirror, presto, refresh-packagekit
repo id                   repo name                              status
adobe-linux-i386          Adobe Systems Incorporated             enabled:     17
chromium                  Chromium Test Packages                 enabled:      7
fedora                    Fedora 11 - i386                       enabled: 13,289
rpmfusion-free            RPM Fusion for Fedora 11 - Free        enabled:    377
rpmfusion-free-updates    RPM Fusion for Fedora 11 - Free - Upda enabled:    210
rpmfusion-nonfree         RPM Fusion for Fedora 11 - Nonfree     enabled:    110
rpmfusion-nonfree-updates RPM Fusion for Fedora 11 - Nonfree - U enabled:    115
updates                   Fedora 11 - i386 - Updates             enabled:  3,451
repolist: 17,576
  1. The names on the left are the repo ids. To disable a particular one, for example rpmfusion-nonfree-updates while doing updates, run your yum like this:-
# yum upgrade --disablerepo=rpmfusion-free-updates
  1. This will help you upgrade the rest of the packages in the mean time.

Configure a Caching-Only Name Server in a Chroot Environment for Fedora 11

| Comments

Having a caching only name-server on your local Machine speeds up your browsing. Here’s how to set up a slightly more secure caching server using ISC Bind in Fedora 11.

  1. Install bind and bind-chroot packages
# yum install bind bind-chroot
  1. Edit your `/etc/sysconfig/named file.
# vim /etc/sysconfig/named

Add the following line:

ROOTDIR="/var/named/chroot"

`

  1. Edit your /etc/named.conf file.
# vim /etc/named.conf
  1. Change the following line:
listen-on port 53 { 127.0.0.1; };

to

listen-on port 53 { any; };

This allows the bind daemon to listen on all your network IPs, not just your loopback(127.0.0.1) address.

  1. Change this line:
allow-query     { localhost; };

to

allow-query     { 192.168.0.0/24; };

You now allow all the machines in your home LAN to use your DNS server.

  1. Make sure it starts at boot time.
# chkconfig named on

Restart your DNS server.

# service named restart
  1. Make sure its listening on the correct ports.
# netstat -ntupl | grep named

In my case, the DNS server IP is 192.168.0.10. So, as seen here, the line udp 0 0 192.168.0.10:53 0.0.0.0:* 2851/named shows it is listening correctly.

  1. Then test your server from another machine in your network. Most probably another linux box or laptop.
# dig @192.168.0.10 google.com

The dig command, with the ‘@’ instructs it to get the IP address for google.com from your newly set up server. On my machine, it looked like this:-

[root@atreides ~]# dig @192.168.0.10 google.com  
; < <>> DiG 9.6.1-RedHat-9.6.1-2.fc11 < <>> @192.168.0.10 google.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER< <- opcode: QUERY, status: NOERROR, id: 6515
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 4, ADDITIONAL: 0  
;; QUESTION SECTION:
;google.com.            IN  A  
;; ANSWER SECTION:
google.com.     300 IN  A   74.125.127.100
google.com.     300 IN  A   74.125.45.100
google.com.     300 IN  A   74.125.67.100  
;; AUTHORITY SECTION:
google.com.     171853  IN  NS  ns3.google.com.
google.com.     171853  IN  NS  ns1.google.com.
google.com.     171853  IN  NS  ns2.google.com.
google.com.     171853  IN  NS  ns4.google.com.  
;; Query time: 82 msec
;; SERVER: 192.168.0.10#53(192.168.0.10)
;; WHEN: Sat Jul 18 20:14:59 2009
;; MSG SIZE  rcvd: 148

Note the SERVER: line. that shows you the answer for the query came from my DNS server (192.168.0.10).

  1. Finally, set up your /etc/resolv.conf accordingly.
    On the server:
nameserver 127.0.0.1

And on all your other machines:

nameserver 192.168.0.10

Change Your MAC Address in Linux

| Comments

Some times it necessary to change your network MAC address on your linux box.

Unlike Windows, which requires some registry editing or even specialized tools, its just a command line away in Linux.

For example, lets change the MAC address of your first netwrok card, usually called eth0.

Let’s swith to being the root user and view the current MAC address:-

ifconfig eth0

You should get something similiar:-

[root@rhel-5new ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 08:00:27:2C:D2:B5  
          inet addr:192.168.0.108  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe2c:d2b5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:20545 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18348 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:10083277 (9.6 MiB)  TX bytes:7489363 (7.1 MiB)
          Interrupt:11 Base address:0xd020 

The MAC address is listed next to the HWAddr column, which is 08:00:27:2C:D2:B5 in this case.

We’ll change it. First shutdown the network interface.

ifconfig eth0 down

Now change it to say, 08:00:27:2C:D2:B4.

ifconfig eth0 hw ether 00:00:27:2c:d2:b4

Bring the interface back up.

ifconfig eth0 up

Finally, lets have a look at the new mac address.

[root@rhel-5new ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:00:27:2C:D2:B4  
          inet addr:192.168.0.108  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::200:27ff:fe2c:d2b4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:20957 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18642 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:10146055 (9.6 MiB)  TX bytes:7520724 (7.1 MiB)
          Interrupt:11 Base address:0xd020 

You can see that the HWaddr field now reports 00:00:27:2C:D2:B4.

Find a Cheap VPS Hosting Provider

| Comments

With VPS hosting becoming a more popular option among the techies, I’ve been tempted to get one. Among the reasons you’ve like to get a VPS include:-

  • You need root access
  • You wish to install a distro of your choice
  • Want more capabilities than offered by standard shared hosting
  • You have Ruby On Rails or Python Based Web Apps you want to host
  • Because you can :D

This diagram, taken from Google Trends shows VPS Hosting search to be picking up since late 2004. I think is times pefectly with the release of Ruby On Rails to the masses. [caption id=”attachment_221” align=”aligncenter” width=”300” caption=”VPS Hosting Search Trends Based on Google Trends”]VPS
Hosting Search Trends Based on Google Trends[/caption]

Anyway, I found this site with cheap VPS hosting, some going for as low as US$3 a month. The reliability of these providers maybe questionable, and I don’t think they can compare to the big guns.

Here’s the link, do comment on your experiences.

sigh Now to prepare for trackbacks from bots tracking the word VPS :P

Check Your Spelling in Linux Using the Command Line

| Comments

You can do a spell check on from the command line in Linux.

First, make sure you have aspell installed. In Fedora, just yum install it.

$ yum install aspell

You’ll also need a dictionary, from which aspell can search for words. A yum search aspell will give you a list.

[raja@atreides visilon]$ yum search aspell
-----------------------------------------------------------
aspell-af.i586 : Afrikaans dictionaries for Aspell
aspell-bg.i586 : Bulgarian dictionaries for Aspell
aspell-br.i586 : Breton dictionaries for Aspell
aspell-ca.i586 : Catalan dictionaries for Aspell
aspell-cs.i586 : Czech dictionaries for Aspell
aspell-cy.i586 : Welsh dictionaries for Aspell
aspell-da.i586 : Danish dictionaries for Aspell
aspell-de.i586 : German dictionaries for Aspell
aspell-el.i586 : Greek dictionaries for Aspell
aspell-en.i586 : English dictionaries for Aspell
aspell-es.i586 : Spanish dictionaries for Aspell
aspell-fr.i586 : French dictionaries for Aspell
aspell-ga.i586 : Irish dictionaries for Aspell
aspell-gl.i586 : Galician dictionaries for Aspell
aspell-hr.i586 : Croatian dictionaries for Aspell
aspell-id.i586 : Indonesian dictionaries for Aspell
aspell-is.i586 : Icelandic dictionaries for Aspell
aspell-it.i586 : Italian dictionaries for Aspell
aspell-no.i586 : Norwegian dictionaries for Aspell
aspell-pl.i586 : Polish dictionaries for Aspell
aspell-pt.i586 : Portuguese dictionaries for Aspell
aspell-ru.i586 : Russian dictionaries for Aspell
aspell-sl.i586 : Slovenian dictionaries for Aspell
aspell-sr.i586 : Serbian dictionaries for Aspell
aspell-sv.i586 : Swedish dictionaries for Aspell
aspell-fo.i586 : Faeroese dictionaries for Aspell
aspell-gd.i586 : Gaelic dictionaries for Aspell
aspell-nl.i586 : Dutch dictionaries for Aspell
aspell-ar.i586 : Arabic dictionary for Aspell
aspell-bn.i586 : GNU Aspell Bengali Dictionary Package
aspell-gu.i586 : GNU Aspell Gujarati Dictionary Package
aspell-he.i586 : Hebrew dictionary for Aspell
aspell-hi.i586 : GNU Aspell Hindi Dictionary Package
aspell-ml.i586 : GNU Aspell Malayalam Dictionary Package
aspell-mr.i586 : GNU Aspell Marathi Dictionary Package
aspell-or.i586 : GNU Aspell Oriya Dictionary Package
aspell-pa.i586 : GNU Aspell Punjabi Dictionary Package
aspell-sk.i586 : Slovak dictionaries for Aspell
aspell-ta.i586 : GNU Aspell Tamil Dictionary Package
aspell-te.i586 : GNU Aspell Telugu Dictionary Package

That’s a lot of languages. I’ll just install the English dictionaries.

yum install aspell-en.i586

Now the fun part. Checking your spelling via command line. Just type aspell -a and it will give you a prompt. I’ll intentionally type a misspelled word and see what it returns:-

[raja@atreides visilon]$ aspell -a
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.6)
psychatrist
& psychatrist 5 0: psychiatrist, psychiatrists, psychiatrist's, psychiatry's, psychiatric

I spelt ‘psychiatrist’ wrongly, and it gave me back a few suggested corrections. (Ok I admit, I didn’t know how to spell it in the first place. :P )

Lets see what happens when you give it a correctly spelled word:-

[raja@atreides visilon]$ aspell -a
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.6)
disapprove
*

Yes, it returns an asterisk(*), showing you’re spelling is correct. Press Ctrl + D when you’re done, to bring you back to the command line.

If you have a text file, you could check that using aspell as well. For example, here’s some sample text:-

Mary had a little lamb. It's fleede was whote as snow.

We’ll save it as mary.txt and run aspell like this to check the file:

aspell check mary.txt

You’ll get a interface like this, highlighting every misspelled word, with the suggested actions. [caption id=”attachment_217” align=”aligncenter” width=”300” caption=”Aspell in action”]Aspell in
action[/caption]

When done with the checking, aspell will exit, saving the previous copy with a .bak extension. :)