5. October 2010 10:00

Linux Install-Event vom alt.comp.hsr

Linux Install-Event

Gestern war wieder einmal der alljährlich stattfindende Linux Install-Event, bei welchem wir vom alt.comp.hsr die neuen Studenten der HSR in die wunderbare Linux-Welt einführen. Bislang hielt sich der Ansturm bei solchen Veranstaltungen arg in Grenzen, nicht so gestern.

Schon als wir um 15.00 Uhr das Zimmer öffneten waren dort die ersten drei Studenten, welche einige Linux-Fragen an uns hatten. Wir hatten schlussendlich ca. 15 Studenten zu Gast welche uns mit unterschiedlichsten Fragen auf Trab hielten. Die meisten waren dank unserem Wiki schnell und einfach zu beantworten für andere wurden man-Pages und das gute alte Internetz zu Hilfe genommen.

Alles in allem ein gelungener Anlass, der gezeigt hat, dass das Interesse an Linux vorhanden ist und vor allem auch das Bedürfnis nach einem Ort, an dem man einfach Fragen stellen kann.


Tags:  HSR  Linux 
Comments
9. November 2009 15:22

Extract .tar.gz to specific directory

I want to extract all files form a “.tar.gz” file to a specific directory (not the current).

When you ask Google you quickly come up with the elegant solution:

$ gzip -cd /some/dir/something.tar.gz | tar -xvf - -C /specific/directory

Somehow my development machine doesn’t accept this, as I keep getting the error:

File -C not present in the archive.
File /specific/directory not present in the archive.

I couldn’t find the answer, but as usual many ways lead to Rome. I’m able to extract the files to the current directory using

$ gzip -cd /some/dir/something.tar.gz | tar -xvf -

Therefore I can simply change the current directory to my specific directory and after the extraction return to the prior directory (I need to unzip the file in a script, therefore I need a generic approach). When we put all that together the following finally works:

$ cd /specific/directory && gzip -cd /some/dir/something.tar.gz | tar -xvf - && cd -

Tags:  Linux 
Comments
23. October 2009 15:20

Insert text at top of a file

If you want to insert text at the end of a file (“append”) you can simply use:

 $ echo "test" >> my_file.txt

which then adds “test” on a new line at the end of the “my_file.txt”. In my case I had to insert text at top of a file. If you start to google for that you discover quite fancy solution like using vi or some sed magic.

For me this was all too much. I have a file with quite static text in it. At the end of a shell script I want to insert the content of this file at the beginning of a logfile created by the script.

When using files it’s getting easier:

 $ cat my_static_file.txt logfile.txt > temp_logfile.txt 
 $ mv temp_logfile.txt logfile.txt

But my script can run parallel and therefore this approach is very dangerous. I was looking for a quick solution and came up with this:

 $ cat my_static_file.txt logfile.txt > $$ && mv $$ logfile.txt

This has the advantage of being on a single line and using “$$” as filename. $$ is the process ID (PID) of the current running script, and therefore cannot exist twice at the same time.

Because of the usage of && and calling everything on one line is, that the following command is only executed when the predecessor command finished successfully. Otherwise the whole command quits. In my case this means the logfile will be kept and not moved.


Tags:  Linux 
Comments
23. October 2009 15:19

Delete all symlink of a directory

It seems like a simple task, and it really is. But I always have to google for such simple stuff, that’s why I start to post things here, so I don’t have to look up the same things over and over again.

To list all files of a directory you can use (sort by date)

 $ ls -lt
total 35
lrwxrwxrwx   1 oracle   dba           13 Jan 30 09:47 etc -> /etc/
drwxr-xr-x   2 oracle   dba         8192 Jan 29 11:40 data
drwxr-xr-x   2 oracle   dba         8192 Jan 29 11:23 info
drwxr-xr-x   2 oracle   dba         8192 Jan 20 15:27 main
-rwxr-xr-x   1 oracle   dba         2643 Dec 18 15:11 run.sh
drwxr-xr-x   2 oracle   dba         8192 Nov 20 14:16 _old

As you can see the symlink is marked with the “l” at the beginning, you can use that to get only links in the output using grep:

 $ ls -lt | grep '^l'
lrwxrwxrwx   1 oracle   dba           13 Jan 30 09:47 etc -> /etc/

To delete the files we are only interested in the filename this can be done using awk. Finally xarg is a tool that runs a given program on every element of it’s input, so the final task can be done by:

 $ ls -lt | grep '^l' | awk '{ print $9 }' | xargs rm

Tags:  Linux 
Comments
23. October 2009 12:44

Using Pidgin with msn-pecan

Today when I was starting pidgin I could connect to ICQ, but when trying to connect to MSN Pidgin comes up with:

unable to retrieve MSN address book

So I was googeling a little bit and found a bug @ pidgin from yesterday. The problem is not pidgin, although the official MSN client and some others clients still work (e.g. meebo). There are several different versions of the MSN protocol, pidgin is using MSNP15. And exactly this protocol is currently not working on the server side @ Microsoft (as it seems).

Other clients are not affected as they switch to older version of the protocol, which are still working.

Because I don’t want to wait until MS fixed the problem, I use a quick workaround. As an alternative you can install msn-pecan.

With Gentoo this works (after adding “x11-plugins/pidgin-msn-pecan ~x86” to /etc/portage/package.keywords):

# emerge pidgin-msn-pecan

After the installation just restart Pidgin go to “Accounts” -> “Manage Accounts”. Select your MSN-Account, click “Modify”. Choose “WLM” as protocol. Save and reconnect your MSN account. Works like a charm!


Tags:  MSN  Linux 
Comments
23. October 2009 12:44

dvd::rip and gentoo

dvd::rip (or dvdrip at the gentoo repository) is a very comfortable ripping software to bring your DVDs on your harddisk.

When I emerged it and wanted to rip a dvd, I just got no result.

  1. the logfile showed no error
  2. in the status bar the text appeared Grab preview - title #3 Duration: 00:01 [Error]
  3. dvd::rip did nothing.

The chapter has been ripped and the file existed on the filesystem, but I was unable to transcode it or do anything else with dvd::rip.

A lot of googling did not provide the solution, but finally I saw that dvd::rip prints the exact command that is executed in the logfile, so I tried to run it manually to eventually see an error.

And then there was theerror:

convert: no decode delegate for this image format `/tmp/dvdrip24111.snap/snapshot001.png'.

I quick search with that showed me, that the problem was imagemagick, which obviously did not have png support. I added the USE-flag “png” to imagemagick in /etc/portage/package.use and re-emerged imagemagick.

Another problems was that transcode was missing the “mp3” USE-flag.

Since then dvd::rip just works!


Tags:  Linux 
Comments
23. October 2009 10:39

Doom for Sysadmins

Das Projekt Doom for Sysadmins lässt Kinderträume wahr werden: Wenn man es startet findet man sich in der Doom-Welt (ja, der Shooter Doom) und kann alle Prozesse die auf dem System laufen “killen”, bzw. durch verwunden “renicen”.

Ach das Admin-Leben ist schön, den ganzen Tag schiessen und Räume voller Monster überprüfen. Sobalds zu viele sind: losballern!


Tags:  Games  Linux 
Comments
23. October 2009 10:25

Find old Files and their size

The first part is clear, find the old files like that:

find . -type f -mtime +365 -print

This gets all Files (-type f, -type d for directories) in the current directory (.) older than a year (-mtime +365) and prints them on stdout (-print)

to delet them, just use:

find . -type f -mtime +365 -exec rm {} \;

But if you want to use them further, a pipe will help you. For any reasons (I don’t know) this is not possible with the -print command. My Solution was the following:

find . -type f -mtime +365 -exec echo {} \;

Now, because there are possibly many many many files, it’s best to use xargs for the argument handling. I use du -ch to determine the file-size and the total:

find . -type f -mtime +365 -exec echo {} \; | xargs du -ch

This should help, Google helped me half-way out, the rest is a little command line magic.

Note: In my case there where really too many files, so that the whole command ended with a broken pipe. I used -type d to reduce the amount of arguments, the disadvantage is that directories are not necessary the same age as the files within.


Tags:  Linux 
Comments