Skip to content

Archive for May, 2009

Free

May 17 09
by mat

Using the free command gives output something like this (-m just tells free to output in megabytes):

free -m
total used free shared buffers cached
Mem: 2013 1996 17 0 27 1381
-/+ buffers/cache: 588 1425
Swap: 956 0 956

This is useful but annoying as it doesn’t show you how much memory is actually free. Files that are used are kept in the ram (referred to as caching). If the memory is needed it is simply overwritten, however if the file is used again it is already in the memory which saves time.

I wrote a quick little bash line to get the actually memory in use or the actual memory free. I use grep to select the right line from the output of free, and then use awk to do the string manipulation and math.

Memory in use

free -m | grep Mem | awk ‘{x=$3-$7; print x}’

Memory free

free -m | grep Mem | awk ‘{x=$2-($3-$7); print x}’

Karamba – System Monitor Basis

May 17 09
by mat

karamba1

I posted my superkaramba system monitor on kde-look.org. Hopefully it will be useful to some people as a basis for their own system monitors. Note that it’s transparent not grey, so looks a little better with the whole screen included in the second picture.

karamba

apt – no public key error

May 17 09
by mat

If you add a new repository to apt (/etc/apt/sources.list) you may get the following error when running ‘sudo apt-get update':

Reading package lists… Done
W: There is no public key available for the following key IDs:
[Key]
W: You may want to run apt-get update to correct these problems

As you probably already guessed, running ‘sudo apt-get update’ will result in exactly the same problem. This is because the new repository’s key needs to verified. This is done by the following:

gpg –keyserver subkeys.pgp.net –recv [Key]
gpg –export [Key] | sudo apt-key add –

replace [Key] with the key you want to add

This can also be made slightly easier by using a bash variable:

$1=[key]
gpg –keyserver subkeys.pgp.net –recv $1
gpg –export $1 | sudo apt-key add –

replace [Key] with the key you want to add

or as a bash script:

#!/bin/sh
gpg –keyserver subkeys.pgp.net –recv $1
gpg –export $1 | sudo apt-key add -

ran by the following:

./key [key]

replace [Key] with the key you want to add
which then you could place in /bin so you could simply run

Script can be downloaded here

Bash: mass image and video conversions

May 16 09
by mat

Linux has many useful command line programs that will convert from one file format to another.

  • convert – converts images (part of ImageMagick)
  • convert input.jpg -resize 500×500 output.jpg

    converts input.jpg to output.jpg resized to 500 by 500 pixels

  • mencoder – converts video files
  • mencoder -ovc lavc -oac mp3lame -o output.avi input.flv

    converts input.flv to output.avi

    Now lets look at some bash:

    for i in *.jpg; do echo $i; done

    This is a for loop which will assign and iterate over a variable i to every item it finds that matches *.jpg in the current directory. It will simple echo the name of the file to the console and then finish. Only really useful for testing the command works, now lets put a conversion command in instead of the echo.

    for i in *.jpg; do convert “$i” -resize 500×500 “x_$i”; done

    This will take every jpg in the current directory resize it to 500 by 500 pixels and then save it as with and x_ prefixing the filename. You can get it to overwrite the current file by making the input and output file names equal (in this case it simple means removing x_ from the above code)