Here is a script to clean up a directory, by deleting files older than a certain date:

#!/bin/bash

DIR=~/Download/

# delete files older than 7 days

find $DIR -mtime +7 -exec rm '{}' \;

# delete empty directories

find $DIR -depth -type d -empty -exec rmdir '{}' \;

Permalink | Leave a comment, tiger

Posted: 17 April 2012 @ 12:12 BST



When installing postgresql be aware that if you have several server instances on the same machine, then postgresql will manage the ports on which each server listens by itself.

From the Debian README:

Please note that the pg_* tools automatically manage the server ports unless you specify them manually. The first cluster which is ever created (by any major version) will run on the default port 5432, and each new cluster will use the next higher free one.
Please use "pg_lsclusters" for displaying the cluster <-> port mapping, and please have a look at the pg_createcluster manpage (the --port option) for details.

The output from pg_lsclusters will look something like this:

Version Cluster   Port Status Owner    Data directory                     Log file
8.2     main      5432 down   postgres /var/lib/postgresql/8.2/main       /var/log/postgresql/postgresql-8.2-main.log
8.4     main      5433 online postgres /var/lib/postgresql/8.4/main       /var/log/postgresql/postgresql-8.4-main.log
Tags: postgresql

Permalink | Leave a comment, tiger

Posted: 9 April 2012 @ 15:33 BST



Like this:

cdrecord -v dev=/dev/cdwriter isofile.iso

Hat tip.


Permalink | Leave a comment, tiger

Posted: 1 April 2012 @ 09:13 BST



Do a screen shot from the command line with ImageMagick like this:

import MyScreenshot.png

After hitting return on this command, you draw the portion of the screen you want grabbed with the mouse.

To make a delay while you open windows or something:

sleep 10; import MyScreenshot.png

To take a shot of the entire screen with a delay of 10 seconds:

 sleep 10; import -window root MyScreenshot2.png

Hat tip.


Permalink | Leave a comment, tiger

Posted: 29 March 2012 @ 15:29 BST



Like this:

convert maphoto.jpg -resize 800x600 -strip -quality 50 -interlace line imageweb.jpg

Hat tip.


Permalink | Leave a comment, tiger

Posted: 19 March 2012 @ 16:05 GMT



Like many people I use calibre as my ebook viewer. Yet, this program is slowly becoming a living nightmare. First is the root exploit. Second is the way that calibre wants to take over every single file. Almost all my files were defaulting to being opened in calibre. Why on Earth would I want an openoffice document opened in calibre? The creators of calibre think I do.

This obviously required fixing.

The file /usr/local/share/applications/defaults.list looks like this:

[Default Applications]
application/x-sony-bbeb=calibre-gui.desktop;calibre-lrfviewer.desktop;calibre-ebook-viewer.desktop
application/x-ruby=calibre-gui.desktop;calibre-ebook-viewer.desktop
text/rtf=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/pdf=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/x-cbz=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/x-mobipocket-ebook=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/x-cbr=calibre-gui.desktop;calibre-ebook-viewer.desktop
text/fb2+xml=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/vnd.oasis.opendocument.text=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/epub+zip=calibre-gui.desktop;calibre-ebook-viewer.desktop
text/plain=calibre-gui.desktop;calibre-ebook-viewer.desktop
text/html=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/xhtml+xml=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/ereader=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/oebps-package+xml=calibre-gui.desktop;calibre-ebook-viewer.desktop

This is a nonsense. It has been setup to open plain text, html and pdfs in calibre. How totally stupid! It needs editing. This is better:

[Default Applications]
application/x-sony-bbeb=calibre-gui.desktop;calibre-lrfviewer.desktop;calibre-ebook-viewer.desktop
application/x-cbz=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/x-mobipocket-ebook=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/x-cbr=calibre-gui.desktop;calibre-ebook-viewer.desktop
text/fb2+xml=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/epub+zip=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/ereader=calibre-gui.desktop;calibre-ebook-viewer.desktop
application/oebps-package+xml=calibre-gui.desktop;calibre-ebook-viewer.desktop

Then run sudo update-desktop-database. That seems to fix it.


Permalink | Comments(3)

Posted: 8 December 2011 @ 14:42 GMT



An educational institution wrote to me recently asking me to finish my degree. I ordered the prospectus and looked through the courses that passed themselves off as computer science. Very little of it was science and rest was even less about computers. In fact, I can know more and get better information by reading the right books and blogs.

It was interesting to see that others have a similar take on computer science education:

When I started college, it was as a computer science major. I thought I would use college mostly as a convenient way to learn some programming languages and strategies so I could get a degree and a job in the field. But I arrived already burnt out and ended up switching out after a semester, for two very different reasons.
The first is the state of technology today. We don’t deal with the machine; we don’t even deal with abstractions on top of the machine. We deal with layers of abstractions, layers piled so high you can’t even see where they end.
The other reason, of course, is that technology education is bullshit. I can pinpoint exactly the moment of my burnout: it was when, as a sophomore in high school, I used the conditional operator in a program for my AP Computer Science class and got marked down...

The school that asked me to complete my degree wants more students. To get them, it has dumbed its courses so that they appeal to any half-wit on the Interwebs with a pulse. The question for me is whether it's worth my time and money.


Permalink | Leave a comment, tiger

Posted: 17 October 2011 @ 14:11 BST



Recently my favourite terminal emulator got deleted from my system, because of the continuing problems I am having due to the non-functioning of KDE.

I came across this interesting discussion on the best terminal emulators. Here are the favourites:

  • yakuake (depends on kde though)
  • tilde (depends on gnome though)
  • rxvt or urxvt or mrxvt - nice and lightweight
  • xterm (the basic)
  • Guake
  • LXTerminal
  • yakuake (depends on kde though)
  • Terminator
  • aterm

Permalink | Leave a comment, tiger

Posted: 8 August 2011 @ 11:45 BST



Here's a simple dictaphone :) you can use from the command line.

sudo aptitude install sox

To record:

rec my_really_important_thoughts.wav

To play back:

play my_really_important_thoughts.wav

Permalink | Leave a comment, tiger

Posted: 21 July 2011 @ 10:52 BST



Everyone should learn sed, especially me:

sed '/use Moose::Policy/ d; /use Moose;/ a \
use MooseX::FollowPBP; \
' lib/interestingfile.pm

and even better:

find lib -name '*pm' -exec sed -i '/use Moose::Policy/ d; /use Moose;/ a \
use MooseX::FollowPBP; \
' '{}' \;

In relation to sed the -i switch means amend the file in place. The 'd' command is delete the line with the preceeding match and the 'a' command means append the following line after the preceeding match.


Permalink | Leave a comment, tiger

Posted: 20 July 2011 @ 20:34 BST



When I use rsync to copy a directory structure I often use the avz options. The a option is key as it tries to preserve everything. It is equivalent to -rlptgoD.

r
means recurse through subdirectories.
l
means recreate symlinks.
p
means preserve permissions.
t
means transfer modification times.
g
means destination group to be same as original group.
o
means preserve owner.
D
means preserve devices and specials.

When you are copying to a usb mounted vfat file system a a lot of these are inappropriate, particular, l, p, g, o and D.

So, in future when trying to copy a directory structure to a vfat file system I'll try this instead:

rsync -rtvz /source/ /destination/

Permalink | Leave a comment, tiger

Posted: 27 June 2011 @ 13:08 BST



The great hal-ectomy is still causing me problems. I found that usb vfat disks were being mounted twice at two different mount points.

This fixed the problem:

sudo aptitude remove halevt

Permalink | Leave a comment, tiger

Posted: 25 April 2011 @ 17:14 BST



Some media players can't play protected m4a's. This script converts the m4a passed on the command line to an mp3 that can then be copied to your selected media player:

#!/usr/bin/bash
#
# copy and convert
#
# Transcode m4a file to mp3
#
# This script is heavily based on the original here:
# http://www.minigeek.org/2007/07/linux-m4a-to-mp3-conversion-script
#
# Naturally, changes are licensed under the GPL
#

orig=$1
temp_wav=`tempfile --directory ~/tmp --suffix=".wav"`

mp3=`echo "$orig"|sed -e 's/\.m4a/\.mp3/'`
temp_trackinfo=`tempfile --directory ~/tmp --suffix=".txt"`

# deal with track info
faad -i ${orig} 2>$temp_trackinfo
sed -i '23s/unknown: /title: /' $temp_trackinfo
sed -i '24s/unknown: /artist: /' $temp_trackinfo

year=`grep 'date: ' $temp_trackinfo|sed -e 's/date: //'`

sed -i 's/unknown: iTunes/iTunes: iTunes/' $temp_trackinfo

genrecount=`grep -c 'genre: ' $temp_trackinfo`
unknowncount=`grep -c 'unknown: ' $temp_trackinfo`

if [ "$genrecount" -eq 1 ] && [ "$unknowncount" -eq 2 ]; then
    sed -i '25s/unknown: /composer: /' $temp_trackinfo
    sed -i '26s/unknown: /album: /' $temp_trackinfo
    genre=`grep 'genre: ' $temp_trackinfo|sed -e 's/genre: //'`
fi

if [ "$genrecount" -eq 1 ] && [ "$unknowncount" -eq 1 ]; then
    sed -i '25s/unknown: /album: /' $temp_trackinfo
    genre=`grep 'genre: ' $temp_trackinfo|sed -e 's/genre: //'`
fi

if [ "$genrecount" -eq 0 ] && [ "$unknowncount" -eq 3 ]; then
    sed -i '25s/unknown: /composer: /' $temp_trackinfo
    sed -i '26s/unknown: /album: /' $temp_trackinfo
    sed -i '27s/unknown: /genre: /' $temp_trackinfo
    genre='other'
fi

if [ "$genrecount" -eq 0 ] && [ "$unknowncount" -eq 2 ]; then
    sed -i '25s/unknown: /album: /' $temp_trackinfo
    sed -i '26s/unknown: /genre: /' $temp_trackinfo
    genre='other'
fi
	
title=`grep 'title: ' $temp_trackinfo|sed -e 's/title: //'`
artist=`grep 'artist: ' $temp_trackinfo|sed -e 's/artist: //'`
album=`grep 'album: ' $temp_trackinfo|sed -e 's/album: //'`
track=`grep 'track: ' $temp_trackinfo|sed -e 's/track: //'`

## convert to wav

faad -o $temp_wav $orig

## convert to mp3
lame --alt-preset 192 --id3v2-only --tt "$title" --ta "$artist" --tl "$album" --tg "$genre" --tn "$track" --ty "$year" "$temp_wav" "$mp3"

## clean-up

rm $temp_wav
rm $temp_trackinfo

exit 0

Permalink | Comments(1)

Posted: 20 April 2011 @ 13:45 BST



I've just spent hours trying to get a nfsv4 mount working, and one of the chief problems was that the documentation is not quite complete.

  1. You need to use nfs-kernel-server, nfs-user-server don't work.
  2. You need to create a phantom filesystem, in my case /nfs4exports, nice and descriptive.
  3. You need to specify the right options in the exports file. Something like:
    /nfs4exports                   hostname(rw,sync,fsid=0,crossmnt)
    
    should do.
  4. Subdirectories to your exports need to have a different fsid, so:
    /nfs4exports/hotsexyillegallydownloadedmusic                   hostname(rw,sync,fsid=1,crossmnt)
  5. You need to use a bind mount to associate your new nfs4 exports tree with your old nfs3 exports. Easiest way to do this is to add to your /etc/fstab:
    /old/nfs/shares /nfs4exports/hotsexyillegallydownloadedmusic none bind 0 0
  6. And most importantly, if you do the step set out in 5, then you need to add the unhide option to your /etc/exports file, so:
    /nfs4exports/hotsexyillegallydownloadedmusic                   hostname(rw,sync,fsid=1,crossmnt,unhide)

The last step is really important otherwise you get a 'stale nfs file handle error'. Why doesn't any of the documentation include this?


Permalink | Leave a comment, tiger

Posted: 14 April 2011 @ 14:10 BST



Sometimes it's just too easy:

ffmpeg -i infile.mp4 outfile.avi

Permalink | Leave a comment, tiger

Posted: 13 April 2011 @ 21:28 BST



Don't mess around with graphical burners that get get in the way of your workspace. Simpler to use the command line:

growisofs -dvd-compat -Z /dev/dvd=/path/to/image.iso

And then while it's happening you can get on with your real work.


Permalink | Leave a comment, tiger

Posted: 4 April 2011 @ 12:29 BST



Like this:

nmap 10.0.0.0/24

Depending on your network setup.

Tags: nmap network ip

Permalink | Leave a comment, tiger

Posted: 1 April 2011 @ 06:52 BST



You are not the root user (and therefore do not have access to blkid), but you want to determine were a particular disk or partition is mounted. You know it is a particular disk, because you have the UUID, which is the quasi-unique identifier for the disk:

mount | grep `readlink -f /dev/disk/by-uuid/xxxxxxxxxxxxxxx` | cut -d ' ' -f 3

Replace the x's with the UUID.


Permalink | Leave a comment, tiger

Posted: 30 March 2011 @ 20:09 BST



Do this:

dpkg --search /etc/udev/rules.d/* | grep 'not found'

Get this:

dpkg: /etc/udev/rules.d/z60_hdparm.rules not found.
dpkg: /etc/udev/rules.d/025_logitechmouse.rules not found.
dpkg: /etc/udev/rules.d/030_ifplugd.rules not found.
dpkg: /etc/udev/rules.d/60-libsane.rules not found.
dpkg: /etc/udev/rules.d/90-local.rules not found.

Find out that orphaned udev rules are making your life difficult.

Grrr.

Tags: dpkg udev

Permalink | Comments(1)

Posted: 25 March 2011 @ 10:25 GMT



You run Debian Sid. You're on the cutting edge. It's where you like to be.

Recently, you found that USB pen drives and hard disks weren't being mounted, or if they were, no user other than root was able to write to them.

You wonder why. HAL, that mainstay of Linux over the last few years, is gone. ivman still appears in the package list, but is not used. The trusty gnome-volume-manager too has disappeared.

You know it's all udev. It's shiny. It's new. It controls the /dev directory and almost all hardware events.

If it's udev that is making your usb disks mount read-only. why?

You turn on 'debug' level logging:

sudo udevadm control --log-priority=debug

More information is now reported to /var/log/syslog. You see lines containing /lib/udev/rules.d/60-persistent-storage.rules and /lib/udev/rules.d/usbmount.rules. You conclude that the udev rules are in /lib/udev

You examine, in particular /lib/udev/rules.d/usbmount.rules which calls the usbmount script to handle the mounting of usb devices. You become concerned that the usbmount package is no longer maintained. But you check the source code. You are relieved to find out that usbmount is a simple script that even you could maintain. You continue to use it.

You read the usbmount documentation, and the configuration options. You realise that the problem is VFAT, an extremely limited and quite rubbish format, that doesn't deal with permissions properly and that, therefore, no one in their right mind should use. Unfortunately, pen drives always use VFAT. You remember the proper way to mount VFAT disks.

You make the following changes to /etc/usbmount/usbmount.conf.

You replace the line:

MOUNTOPTIONS="sync,noexec,nodev,noatime,nodiratime"

With this one:

MOUNTOPTIONS="noexec,nodev,noatime,nodiratime"

And you add this line:

FS_MOUNTOPTIONS="-fstype=vfat,gid=plugdev,dmask=0007,fmask=0117"

Users in the plugdev group can now write to pen drives and other usb VFAT formatted hard drives. You make sure you are in the plugdev group.


Permalink | Leave a comment, tiger

Posted: 24 March 2011 @ 14:30 GMT






Subscribe

 Subscribe via Feedburner in a reader

Enter your email address:

Delivered by FeedBurner

Login
Login:
Password:



Don't have an account?
Sign up to Gnuru.org
Forgot your password?



RSS 2.0 Feed
Sitemap