Linux
How To Configure Wireless / WiFi Networking in Ubuntu via the Command Line (CLI)
There are a number of tutorials available on-line for sorting out WiFi in Ubuntu via the CLI, but most of them seem quite outdated, so I decided to do my own.
I did this on a minimal install of Ubuntu Lucid, so it is as up-to-date as possible. The PC I was using has no Windows Manager of Graphical Display Manager, just the good old terminal so all this is done via the CLI only. I did this using a USB WiFI dongle, but it should be the same whether you use an internal card or a USB card.
First, you need to install the relevant software. You need to have a wired connection at this point, otherwise this wont work.
sudo apt-get install wireless-tools wpasupplicant
If you are connecting to an open network, you wont need wpasupplicant. Next, to make sure your wireless device is working as it should issue:
iwconfig
and then
sudo iwlist scan
This should show you some wireless networks as proof that the WiFi device is working, if something goes wrong here, then there is a problem with your device or driver and you need to get googling.
If you are accessing a secured network and you really should be, you need to access the correct version of your WiFi key. To get your key, issue this command:
wpa_passphrase YOURSSID YOURWIFIPASSWORD
This will result in something that looks like this:
network={
ssid="YOURSSID"
#psk="YOURWIFIPASSWORD"
psk=fe727aa8b64ac9b3f54c72432da14faed933ea511ecab1 5bbc6c52e7522f709a
}
You need to make a note of the long phrase after psk= (NOT #psk=) as this your WiFi password in hex format.
Next, you need to edit your interfaces file, so issue:
sudo nano /etc/network/interfaces
At the end of this file, you need to add your WiFi configuration. Here are the options you can add.
auto wlan0 #change this to the name of your WiFi interface
iface wlan0 inet dhcp #this is normally fine, if you want a static IP address replace “dhcp” with “static”
netmask 255.255.255.0 #change this as appropriate for your network, this value is usually right
gateway 192.168.1.1 #change this as appropriate for your network
address 192.168.1.100 #only needed for a static IP address
dns-nameservers 192.168.1.1 #only needed for a static IP address
wpa-driver wext #you shouldn’t need to change this
wpa-ssid YOURSSID #just type the name of your SSID here
wpa-ap-scan 1 #if the name of your SSID is hidden usually, type 2 instead of 1
wpa-proto WPA #if you use WPA1 type WPA, if you use WPA2 type RSN
wpa-pairwise CCMP #if you use AES type CCMP, if you use TKIP type TKIP
wpa-group CCMP #if you use AES type CCMP, if you use TKIP type TKIP
wpa-key-mgmt WPA-PSK #usually WPA-PSK (if you share a key) but sometimes WPA-EAP (for enterprises)
wpa-psk YOURHEXKEYFROMABOVE #the hex key that you generated earlier
Thus, since I am using a WiFi card that is identified as wlan0 and am connecting to a WPA1 AES encrypted network called MYPLACE that isn’t hidden without a static IP address, this is what I added:
auto wlan0
iface wlan0 inet dhcp
netmask 255.255.255.0
gateway 192.168.1.1
wpa-driver wext
wpa-ssid MYPLACE
wpa-ap-scan 1
wpa-proto WPA
wpa-pairwise CCMP
wpa-group CCMP
wpa-key-mgmt WPA-PSK
wpa-psk 71c81a844973ae7bb1243141e5caa7b6bb0e2d7eetcetcetc
Finally, comment out the top section so it looks like this:
#auto eth0
#iface eth0 inet dhcp
This stops your wired network from working. This helps to ensure there are no conflicts. Remember, if you want your wired network to work again, remove these two comments (the #).
Finally, save the file by pressing CTRL and X and then pressing Y to save to the file. Now, reboot and your network should come up. Yay!
Some people have found that this doesn’t always work, so the next thing to do is to edit the configuration file for the wpasupplicant program. Do this by issuing:
sudo nano /etc/wpa_supplicant.conf
Basically, you add pretty much the same information here as you did to the interfaces file, except without the wpa- part. So, my file looks like this:
ap_scan=1
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="MYPLACE"
scan_ssid=0
psk=71c81a844973ae7bb1243141e5caa7b6bb0e2d7eetcetcetc
key_mgmt=WPA-PSK
proto=WPA
pairwise=CCMP
group=CCMP
}
As far as I am aware, the options are the same. So, edit this file as necessary, make sure you add the ctrl_interface and network={ at the beginning and the } part at the end. Save it and try restarting again. If it still doesn’t work, then kick your PC, wish you had installed Windows 7 instead and go off and do some Googling. You’ll find the answer on the Ubuntu forums and you’ll be happy again.
Best of luck!
FINALLY: A Bash Progress Indicator for ffmpeg that WORKS
I decided to write a progress indicator for ffmpeg video conversions. This was much much much harder than I ever anticipated. I was in for a tough time. Annoyingly, for what ever reason, ffmpeg doesn’t use Carriage Returns and Line Feeds in the expected way when it outputs its output during a conversion, resulting in two days of stress for a noobie bashophile like me.

Eventually, after hours of googling, I came across the solution. This script should be a very accurate indicator of the progress of a ffmpeg video conversion. It currently only tells you how far the conversion has progressed as a percentage, but I will soon add an ETA and time to it as well (now added, see update below). It does this, by looking at the number of frames your input video file has, and then reading what frame ffmpeg is currently on every ten seconds, and printing out the percentage.

You have to put in your own ffmpeg command if you want, mine is just for converting .mpg DVB-T recordings from MythTV to mkv files.
To use the script, call the script with the full path of the file to be converted afterwards, e.g.: “./ffmpeg-progress.sh /home/prupert/FIVE.mpg” and it gives you something like this:
UPDATE:
I have now added an ETA function, which, as far as I can tell, should be pretty accurate, I’ll be testing it tomorrow to see how well it works. It is based on the remaining number of frames to process and the current fps that ffmpeg is working at. I also plan to convert the script to python, if possible, to make it cross platform and give it a GUI. It will also be called YAFF (Yet Another Ffmpeg Frontend).
Essentially, the script turns ffmpeg output from this:
frame=42992 fps= 21 q=29.0 size= 217692kB time=1717.72 bitrate=1038.2kbits/s dup=12 drop=0
frame=43002 fps= 21 q=29.0 size= 217692kB time=1718.12 bitrate=1038.0kbits/s dup=12 drop=0
frame=43018 fps= 21 q=29.0 size= 217756kB time=1718.76 bitrate=1037.9kbits/s dup=12 drop=0
frame=43036 fps= 21 q=29.0 size= 217788kB time=1719.48 bitrate=1037.6kbits/s dup=12 drop=0
frame=43050 fps= 21 q=29.0 size= 217820kB time=1720.04 bitrate=1037.4kbits/s dup=12 drop=0
frame=43062 fps= 21 q=29.0 size= 217852kB time=1720.52 bitrate=1037.3kbits/s dup=12 drop=0
frame=43078 fps= 21 q=29.0 size= 217884kB time=1721.16 bitrate=1037.0kbits/s dup=12 drop=0
frame=43090 fps= 21 q=29.0 size= 217916kB time=1721.64 bitrate=1036.9kbits/s dup=12 drop=0
frame=43106 fps= 21 q=29.0 size= 217948kB time=1722.28 bitrate=1036.7kbits/s dup=12 drop=0
Last message repeated 2 times
[mpeg2video @ 0x8f7ebf0]ac-tex damaged at 15 0
[mpeg2video @ 0x8f7ebf0]concealing 90 DC, 90 AC, 90 MV errors
frame=43122 fps= 21 q=29.0 size= 217981kB time=1722.92 bitrate=1036.4kbits/s dup=12 drop=0
frame=43140 fps= 21 q=29.0 size= 218045kB time=1723.64 bitrate=1036.3kbits/s dup=12 drop=0
frame=43155 fps= 21 q=29.0 size= 218077kB time=1724.24 bitrate=1036.1kbits/s dup=12 drop=0
frame=43168 fps= 21 q=29.0 size= 218141kB time=1724.76 bitrate=1036.1kbits/s dup=12 drop=0
frame=43182 fps= 21 q=29.0 size= 218205kB time=1725.32 bitrate=1036.1kbits/s dup=12 drop=0
frame=43194 fps= 21 q=29.0 size= 218237kB time=1725.80 bitrate=1035.9kbits/s dup=12 drop=0
frame=43207 fps= 21 q=29.0 size= 218269kB time=1726.32 bitrate=1035.8kbits/s dup=12 drop=0
In to this:
/home/rupert/Downloads/Village of the Damned.mpg..mpg has 172447 frames, now converting
ffmpeg PID = 24868
ffmpeg: 43062 of 172447 frames, progress: 24% and ETA: 1h 42m 41s
Which must be a good thing in anyone’s book
The script is hosted at github, enjoy:

YAFF by Rupert Plumridge is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales License
Ubuntu Lynx (10.04 LTS)
I’m a regular user of Ubuntu, using it now on my laptop, one of my work PCs (the other runs XP for Microsoft Office compatibility), my HTPC and my XBMC box. Yeah, I know, I have too many PCs.
It seems Canonical (the developers of Ubuntu) are keen to push the next release, called Lucid Lynx, or 10.4 LTS (Long Term Support). To help the push, they have published a number of badges for websites.
Here are all of them, since I love Ubuntu so much ![]()
Some random Linux tips: mutt 127 exec error and rsync operation not supported error
I’ve been fixing a few issues with my Linux server recently and had to search to find the fixes, so I though I’d post the fixes here.
Up until about a week ago, I was using ssmtp as my mail server to allow my Ubuntu server to email me certain things. It uses the gmail ssmtp server to send me mail. It was working fine for about a year, but suddenly stopped working recently, so I thought I would sort the problem out. I ended up removing ssmtp and installing postfix, which now is installed by default on ubuntu systems, using the guide from here. It worked very well, except my default user wasn’t able to send email using the default mail client I was using (mutt). I kept on getting the same error: Error sending message, child exited 127 (Exec error.)
It turns out I had a .muttrc file in my home folder, from an earlier failed attempt to set up an email server that had some stupid settings, most noticeably a sendmail setting. I simply deleted the .muttrc file and the above error went away.
However, it turned out that installing postfix meant that my server started emailing me whenever cron ran a job from /etc/crontab. Which in some cases was every two minutes! So, I found out that simply adding: " >/dev/null 2>&1 " to the end of every entry would stop the results being emailed to me.
This turned out to be quite useful, since cron emailed me with the results of my daily back up, that uses rsync, saying that it had failed with litteraly hundreds of the following error: /bin/cp: cannot create link Operation not supported some more googling revealed that this usually occurs when cp (copy) is trying to make a symlink on a disk that does not support symlinks, such as a Windows formatted NTFS disk. This was exactly my situation, so I simply reformatted my backup disk using gparted as ext3 and now rsync is much happier.
Automount a drive in Ubuntu
I wrote this as a post on XBMC forum, but I thought I should share the wealth. The following is a guide to automounting a drive in a minimal install of Ubuntu with no GUI or desktop, only CLI access.
To manually get a minimal install of Ubuntu to auto-mount a USB drive at boot:
First off, you need command line access (also called The Terminal) to your installation and also you need to boot WITHOUT your USB drive connected. So, shutdown your box and then disconnect your USB drive. Now restart the box. Then, when XBMC has loaded, press Alt and F7 together, which should bring up a new Terminal screen with a log in.
Then log in using your username and password that you set up when you installed Ubuntu.
Next you need to type the following:
tail -f /var/log/syslog
This basically prints out the system log as it changes. Once you have typed this, plug in your USB drive. You should see a load of new stuff being printed in your terminal, this is the Ubuntu system recognising and loading your USB drive (though not mounting it). You should see something like this:
Jan 8 13:13:34 xpuntu kernel: [ 1671.616121] usb 2-2: new high speed USB device using ehci_hcd and address 5
Jan 8 13:13:34 xpuntu kernel: [ 1671.750917] usb 2-2: configuration #1 chosen from 1 choice
Jan 8 13:13:34 xpuntu kernel: [ 1671.752477] scsi6 : SCSI emulation for USB Mass Storage devices
Jan 8 13:13:34 xpuntu kernel: [ 1671.752815] usb-storage: device found at 5
Jan 8 13:13:34 xpuntu kernel: [ 1671.752820] usb-storage: waiting for device to settle before scanning
Jan 8 13:13:39 xpuntu kernel: [ 1676.753513] usb-storage: device scan complete
Jan 8 13:13:39 xpuntu kernel: [ 1676.754606] scsi 6:0:0:0: Direct-Access WDC WD16 00AABB-56PUA0 7H00 PQ: 0 ANSI: 2 CCS
Jan 8 13:13:39 xpuntu kernel: [ 1676.755793] sd 6:0:0:0: Attached scsi generic sg2 type 0
Jan 8 13:13:39 xpuntu kernel: [ 1676.756402] sd 6:0:0:0: [sdb] 312581808 512-byte logical blocks: (160 GB/149 GiB)
Jan 8 13:13:39 xpuntu kernel: [ 1676.757163] sd 6:0:0:0: [sdb] Write Protect is off
Jan 8 13:13:39 xpuntu kernel: [ 1676.757171] sd 6:0:0:0: [sdb] Mode Sense: 00 38 00 00
Jan 8 13:13:39 xpuntu kernel: [ 1676.757176] sd 6:0:0:0: [sdb] Assuming drive cache: write through
Jan 8 13:13:39 xpuntu kernel: [ 1676.761108] sd 6:0:0:0: [sdb] Assuming drive cache: write through
Jan 8 13:13:39 xpuntu kernel: [ 1676.761119] sdb: sdb1
Jan 8 13:13:39 xpuntu kernel: [ 1676.774572] sd 6:0:0:0: [sdb] Assuming drive cache: write through
Jan 8 13:13:39 xpuntu kernel: [ 1676.774583] sd 6:0:0:0: [sdb] Attached SCSI disk
You want to look out for the reference to “[sd*]“, in my case it is [sdb]. This is the name that Ubuntu has given to your USB drive.
Next stop the tail command, so press:
Ctrl and C
This stops the tail command, then type the following:
sudo blkid
You will have to enter your password. This should give you something like the following:
/dev/sda1: UUID="1024B74F24B73696" TYPE="ntfs"
/dev/sda5: UUID="015273a3-e1a8-4d53-867f-ffec83b3df60" TYPE="swap"
/dev/sda6: UUID="50b2512a-4d07-4a83-860e-be608a5b2cb7" TYPE="ext4"
/dev/sdb1: LABEL="" UUID="48D3-B1C9" TYPE="vfat"
What you see should be different from this. This basically lists all the drives attached to your system, alongside two important pieces of info, the drives UUID number and what the drive is formatted as. You need to find the reference to the “sd*” that you found out earlier, so in my case it is /dev/sdb1. Then, make a note of the UUID number and the TYPE as well, in my case it is vfat.
So, now we know where our USB drive is and what it is called.
Next, we want to tell Ubuntu to automount it each time it boots.
So, you need to edit the /etc/fstab file that tells Ubuntu what drives to mount at boot. Be careful here, don’t delete or change anything that is already in this file, since it will stop your device from booting. It is ok to add new stuff to this file however. To be safe, we shall make a backup of the /etc/fstab file, just incase we mess up. If we do mess up, simple copy this backup over the /etc/fstab file and reboot and everything will be back as we found it. So, to make a backup simple type:
sudo cp /etc/fstab /etc/fstabackup
This copies the /etc/fstab file to /etc/fstabackup, which we can use as a backup.
To edit the /etc/fstab file, you need to use the command line Text editor called Vi ([url]http://en.wikipedia.org/wiki/Vi[/url] and [url]http://www.cs.colostate.edu/helpdocs/vi.html[/url]) I would recommend reading about it first, since it is a bit of an arse to use in Terminal mode.
Start Vi to edit your file using:
sudo vi /etc/fstab
Use your arrow keys to move down to the very end of the file. Then press “a” to Append stuff to the end of the file. Press Return to start a new line and then type the following:
UUID=YOURUUIDNUMBERHERE /home/xbmc/usb vfat defaults 0 0
Add your own UUID number after the = and change the TYPE if yours wasn’t vfat. /home/xbmc/usb is where you will be mounting your USB drive, this can be anything you want, but to make your life easy, since XBMC defaults to showing your home directory in the file browser, put it under your home directory, so in my case, the main user on my box is xbmc, so I use /home/xbmc/usb.
Press Enter again after typing that, then press Escape, then press and hold Shift and press Z twice, this saves and exits Vi.
Next, you need to make the folder that the drive will be mounted in, so type:
mkdir /home/xbmc/usb
Replace /home/xbmc/usb with whatever you put in the /etc/fstab file earlier.
Finally, that is it. Hopefully, if all went well, you can now simply reboot, with your USB drive attached, and the drive will be found at /home/xbmc/usb which you can navigate to from XBMC.
Best of luck!!
Getting Conky and Ubuntu 9.04 to play nice
Ever since the most recent upgrade to Ubuntu (9.04) my conky installation just has not been happy. I am guessing it is something to do with the fancy desktop effects provided by Compiz, and until there is a fix, you kinda have to implement a hack.
First, the only way to ensure that conky doesn’t overlay ALL your windows, is to use these settings in your .conkyrc:
# Create own window instead of using desktop (required in nautilus)
own_window yes
# If own_window is yes, you may use type normal, desktop or override
own_window_type override
Then, you need to create a little script that you run each time you boot up your computer. The script has to say:
killall conky
conky
Run this script after the computer has booted up, and conky behaves nicely, and stays on the desktop as it is meant to.
If anyone has a better solution than this then give me a shout, but this is the only way I have found of getting conky to not sit on top of everything else, not blank out all icon on the desktop, or not completley dissapear
fsck.ext3: Bad magic number in super-block
So, every so often after upgrading my Ubuntu server, I occasionally get an error during boot, saying the following:
fsck.ext3: Superblock invalid, trying backup blocks…
fsck.ext3: Bad magic number in super-block while trying to open /dev/sdc1
fsck died with exit code 8
After some rooting around, it turns out to be an error on my part. It is all down to my /etc/fstab file (a text file which tells Ubuntu how and where to mount all the hard drives in your system). A while ago, Ubuntu changed the way it records drives details, whereas it use to use /dev/sdX to refer to a drive (with X being a-z) it now uses UUIDs instead. These are unique ID numbers that the system gives to a drive. It changed from /dev/sdX to UUID since occasionally the sdX number would change upon a reboot.
This was exactly what was happening to me. In my fstab file I used /dev/sdc1 to refer to one USB hard drive, and a UUID to refer to another. fstab correctly mounted the UUID drive, but the /dev/sdc1 had changed from the original USB drive it referred to, to the same USB drive that I mounted via the UUID number, thus it failed to mount. When fsck (Ubuntu’s file checking program) runs, it uses fstab to find out info about the hard drives you have. If you have a situation like mine where two entries where referring to the same hard drive, fsck freaks out and dies, thus the error.
To fix this, you need to edit your fstab. Now, if you are lucky, you can simply type EXIT at the prompt you get when this error occurs and the system will boot up. If not, I’d recommend using an Ubuntu LiveCD to boot up the system and then edit your fstab file.
So, open /etc/fstab in a text editor, make sure you use a user with the correct privileges to do this. Then, open a command prompt and type
sudo fdisk -l
This will list all your hard drives, allowing you to identify them. Next, type:
sudo blkid
This will list all your hard drives and their UUID numbers.
Using the info from the first command, fdisk and the UUID number from the second command, blkid, you can work out which device has which UUID number. Then make sure in your /etc/fstab file, you refer to devices using UUID=XXXXXXXXXXXXXXX instead of /dev/sdXX.
This way, your disks will always mount correctly and you shouldn’t get anymore fsck errors on boot, well until your hard drive dies lol!
Finding missing packages when building from source on Ubuntu
So, you are building a program from source on Ubuntu and you have run into dependency issues, what do you do?
One solution is to use apt-file. Install this with sudo apt-get install apt-file. Then run apt-file update to update it’s cache. Now, you can use it to search for your missing dependencies by running apt-file search mymissingfile.so (replace mymissingfile.so with whatver you want) and it will show you what packages provide that dependency. The go ahead and install that package to solve your problems, it even shows you where that dependency is installed to!
Bluetooth controlled motion start-up script
So, after messing with ZoneMinder and creating a bluetooth script for it, I am now messing with motion instead, and have modified the script accordingly.
For kicks, I have hosted it on google code
http://code.google.com/p/bluetoothmotion/
It also details a fix for the problem with motion on Ubuntu and the /etc/init.d/motion stratup script.
motion 1 zoneminder 0
So, after messing around with ZoneMinder for a few weeks, I finally gave up. I then decided to try out motion instead, which I had heard a lot about, but largely ignored because it didn’t have a fancy website or nice looking web GUI.
Oh how wrong I was. Motion is so much better than ZoneMinder, I am sorry to say. It has a very basic web interface, allowing you to start and stop motion detection and view a live stream from one camera at a time. However, it really beats ZoneMinder into a cocked hat when you look at support for webcams. I had so many problems getting my webcams working in ZoneMinder, but in motion, you just tell it your video device locations (/dev/video0 etc) and off it goes.
There are some additional php packages out there allowing you to create webcam stream montages and view previous alerts created by motion. Although all configuration is done via a text config file, the file is well laid out and well commented and thus easy to understand.
I would highly recommend motion over ZoneMinder and am using it now as my main geek project. I am thus updating my bluetooth script to work with motion and will post the new version soon.

