I have run into a couple of shell scripts that print terminal colours as blocks of colour or text but none have been formatted in a way that showed a terminal colour scheme that well. Recently I have taken up adopting the solarized colour scheme but I’ve been trying to modify it slightly to suit my tastes and have had trouble discerning what colours were what, as some colours are replaced with different shades of grey.

Reading the debian planet I came across Antonio Terceiro’s post on a neat simple shell script to print out all the ANSI colour codes and I really like the formatting, so I want to save it here so I don’t forget.

#!/bin/sh -e
 
for attr in $(seq 0 1); do
  for fg in $(seq 30 37); do
    for bg in $(seq 40 47); do
      echo -n "\033[$attr;${bg};${fg}m$attr;$fg;$bg\033[m " 
    done
    echo
  done
done
 

Occasionally I need to extract a source tarball to a subdirectory without its leading path directory and every time I need it I forget the necessary GNU tar switches, so here is todays lesson in the two tar switches required.

tar --strip-components 1 -xvf package_1.1.tar.bz2 -C package

“–strip-components 1″ will strip off the first (1) folder of the archives path. Replacing 1 with 2 will do the obvious and strip off 2 folders/preceding path components.

“-C package” is nice and simple, it will extract the archive into the folder package. You could be fancy and do “-C ~/source/package” and extract the archive anywhere you fancy.

 

A really simple guide to ripping the audio out of a DVD using transcode to wav or mp3.

http://www.ubuntugeek.com/how-to-rip-dvd-audio-to-mp3-or-ogg.html

 

If you have to install CentOS, or you just want to have a nosey, the best way to install it is using the Netinstall CD.

I followed this little guide: http://www.chrisgountanis.com/technical/45-centos-netinstall.html, and it worked out great.

I chose the raw base system install in the graphical installer. It downloaded about 400-500mb of data, installed the packages and after a quick reboot left me with a console screen in vmware, exactly what I wanted.

The only trick was to make sure I was pointing to the right folder in the mirror’s ftp/http directory.

 

Rxvt is a great terminal. When I needed a light weight terminal that supported unicode on my ye olde laptop, rxvt was the answer.

When combined with the font Terminus it quickly became my terminal of choice on the PC as well, but back to the topic at hand. Using a large monitor resolution leaves alot of unused screen real estate and one of the common action I would do with my terminal windows was to tile them, lining each terminal window up against the edge of the screen, and then dragging them half way.

This quickly becomes rediculous manually adjusting windows each time you boot. I searched for ways of tiling windows in XFCE a number of times but either came across posts about using applications to do the tiling or going the the whole way and using a tiling window manager like awsome.

Fortunately last week while exploring the vast rxvt-unicode documentation, trying to solve another issue I came across the geometry command line option.

My terminal tiling is simply two terminals taking up half the desktop each and I use a seperate shortcut for the tiled windows and a generic window, with XFCE’s window management nicely placing the two terminals side by side.

Here is my tiled rxvt command line options from my terminal shortcut:

rxvt-unicode -bg black -fg white -vb -sl 10000 -fn "xft:Terminus" -geometry 102x62

 

Recently an FTP server I connect to enabled SSL access which is great, FTP needs any extra protection you can give it.

Unfortunately lftp started to hang on ‘FEAT negotiation…’ when non-SSL connections were disabled while ftp:ssl-force was set in ~/.lftp/rc. After doing a little searching on google the I found the extremely simple answer that you need to connect to your SSL enabled ftp servers as

ftps://ftp.domain.com:21

so update your bookmark file (~/.lftp/bookmarks) and get connecting.

Answer found here: http://www.mail-archive.com/lftp@uniyar.ac.ru/msg02576.html

 

Update: Don’t even bother reading this, its way way broken. Updated post here:

http://www.codemonkies.net/linux/index.php/2009/07/21/python-vnstat-offpeak-script-version-2/

 
#! /usr/bin/env python
 
import os
import time
 
hours=[]
totalrx=0
totaltx=0
onpeakrx=0
onpeaktx=0
currenttimehour=time.strftime("%H")
 
vnstat=os.popen('vnstat --dumpdb')
for line in vnstat:
    if line.split(';')[0] == 'h':
        hours.append(line.rstrip())
 
for hour in hours:
    totalrx+=int(hour.split(';')[3])
    totaltx+=int(hour.split(';')[4])
 
for onpeakhour in hours:
    print onpeakhour
    offpeakhours=range(2,8)
    #print(offpeakhours)
    #print onpeakhour.split(';')[1]
    if int(onpeakhour.split(';')[1]) not in offpeakhours:
        #print onpeakhour.split(';')[3]
        #print onpeakhour.split(';')[4]
        onpeakrx+=int(onpeakhour.split(';')[3])
        onpeaktx+=int(onpeakhour.split(';')[4])
        #print("Rx: ",onpeakrx)
        if onpeakhour.split(';')[1] == currenttimehour:
            #print 'Breaking'
            break
 
print "Today:"
print 'Rx: %dMB %dkB' % (totalrx/1024, totalrx)
print 'Tx: %dMB %dkB' % (totaltx/1024, totaltx)
print 'Total: %dMB %dkB' % ((totalrx+totaltx)/1024, totalrx+totaltx)
print "Todays Onpeak:"
print 'Onpeak Rx: %dMB %dkB' % (onpeakrx/1024, onpeakrx)
print 'Onpeak Tx: %dMB %dkB' % (onpeaktx/1024, onpeaktx)
print 'Onpeak Total: %dMB %dkB' % ((onpeakrx+onpeaktx)/1024, onpeakrx+onpeaktx)
 

A couple of years ago my family purchased a Canon MP150, a bog standard multifunction center. It was an impulse buy, so any concern that it may not work in Linux was easily brushed aside, especially since the rest of the family still heavily used Windows XP. And it didn’t work in Linux.

But with great fortune the gutenprint project now (well, really over a year ago, but after the initial searches I gave up looking) supports the Canon MP150 as well as a sizeable list of other Canon printers.

The OpenPrinting-gutenprint drivers in ubuntu do not yet have the Canon drivers so below is how I setup the Canon MP150 driver on Ubuntu Hardy.

Visit http://www.openprinting.org/show_printer.cgi?recnum=Canon-PIXMA_MP150 and download the package you need, rpm or deb, i386 or 64bit, depending on what distro and architechture you are running.

I downloaded the ‘x86 32 bit (DEB for LSB 3.2)’ package and installed it with dpkg:

sudo dpkg -i openprinting-gutenprint_5.2.2-1lsb3.2_i386.deb

The openprinting-guntenprint package installs with all the ppd files compressed with gunzip. I am not sure if this is how they are supposed to be, perhaps more current versions of cups/gnome printer config are able to use them compressed, but in hardy they couldn’t. Instead I uncompressed the driver I needed into the same folder and selected it in the gnome print config.

First find the driver you need in the openprinting-gutenprint driver folder, replace Canon with the folder of printer brand that you are looking for if it is not a Canon printer:

dean@subspace:/opt/OpenPrinting-Gutenprint/ppds/Canon$ ls | grep -i mp150
Canon-PIXMA_MP150-gutenprint.5.2-en.ppd.gz
Canon-PIXMA_MP150-gutenprint.5.2.sim-en.ppd.gz

Next, uncompress the two files with gunzip:

dean@subspace:/opt/OpenPrinting-Gutenprint/ppds/Canon$ sudo gunzip -d Canon-PIXMA_MP150-gutenprint.5.2.sim-en.ppd.gz
dean@subspace:/opt/OpenPrinting-Gutenprint/ppds/Canon$ sudo gunzip -d Canon-PIXMA_MP150-gutenprint.5.2-en.ppd.gz

Now plug the printer in and turn it on, and head to the gnome print config under System -> Administration -> Printing, click New Printer and hopefully it should be at least partially recognised as in the screenshot below.

In your case it may autodetect the driver, in my case it only found the Turboprint driver, ugh. Instead select the Provide PPD file radio button and click on the bar below it with the folder icon. Head to /opt/OpenPrinting-Gutenprint/ppds/Canon in the location bar, or click through the path and select Canon-PIXMA_MP150-gutenprint.5.2.sim-en.ppd, choose Open then Forward.

Give your printer a name, which will appear in any print dialogs for you to choose, and if you want to, describe it as well.

Click Apply and you’re now done! You should see your printer in the list and be able to print a test page, or even try printing documents in all your favourite Linux applications.

 

I came across a handy blog post with a way to change your keyboard layout in X as XFCE doesn’t include any ability to natively do so. A major flaw of using X’s keyboard layout change is that it doesnt change the Control and Meta keys over to the new layout.

Which is a bit of a pain given it works changing layouts with setxkbmap on my debian + xfce ancient laptop and the Ctrl/Meta keys are for the new layout. Unfortunately while xfce works on my laptop, its a touch minimalistic for me to use on my PC, and really the fact that xfce is missing an applet to do this for you is all part of that.

Maybe when I become code-worthy I will hack up a language changing applet for xfce.. and modify all the other little things that annoy me. http://ubuntu.sabza.org/2006/10/13/xubuntu-easily-switch-keyboard-layout/

Edit:

Luckily Alexander Iliev has come along and written a very handy xfce panel app (based off earlier work of Gauvain Pocentek) that will allow you to easily add/remove and change keyboard layouts. I would have to say it was one of last remaining issues stopping me from using XFCE on my desktop and now that I’ve installed Debian on there I use XFCE instead of Gnome. Great stuff.

xfce4-xkb-plugin: http://goodies.xfce.org/projects/panel-plugins/xfce4-xkb-plugin

DV = dvorak keyboard layout

XFCE kb applet

 

While Linux is not known for its instability, every so often something can go wrong and leave you with a frozen system.

Usually, at least for me, a frozen system occurs when modifying core parts of the operating system, such as the kernel, X window system or when performing a complete upgrade such as debian’s dist-upgrade, which includes plenty of changes to core components.

The first thing to try when presented with a frozen screen is to see if just X has crashed and whether you can access a console via ctrl-alt-F1, if you’re presented with the console screen, you can login and relatively cleanly reboot by issuing, sudo reboot -f. If you swap to a console screen from a working X and wish to get back, on most distro’s this is ctrl-alt-F7, if not try the combo with other function keys.

Still stuck staring at a locked screen? Then it is time to try the magic sysreq key. The sysreq key is a kernel function, which must be compiled into the kernel, that allows low level commands to be run. This means you can clean up a system, and force it to reboot/shutdown with out corrupting the filesystem. To issue a magic sysreq key you hold down alt, Sysreq (also the PrintScreen key on most modern keyboards), then the selected key for which command you want issued.

The best series of sysreq keys to issue has luckily been solved by an acronym, created by some one far more creative than me and found on the wikipedia link below.

Raising Elephants Is So Utterly Boring, or BUSIER in reverse.

The series above will do the following:

  1. R: Switch the keyboard from RAW mode to XLATE mode (ASCII Mode, sort of.)
  2. E: Terminate all processes, applications should gracefully close
  3. I: Kill all processes, forcefully terminate all processses
  4. S: Sync/flush data to the disk
  5. U: Unmount all filesystems and remount as read only
  6. B: Reboot the system

A few second pause should be used between each sysreq command issued so they can take full effect.

You will also need to be aware if you’re using a different keyboard layout the keys are based on the QWERTY layout, the matching keys are in the wikipedia link below, which you can also take a look at if you’re interested in the fullset of available sysreq commands.

If nothing happens, unfortunately you’ll have to powercycle and hope for the best, fingers crossed you won’t need the magic sysreq key very often!

http://en.wikipedia.org/wiki/Magic_SysRq_key

© 2012 Linux Sand Garden Suffusion theme by Sayontan Sinha