Archive for the ‘Linux’ Category

Using ‘date’ in cron jobs

23. June 2009

I was trying to backup a file every hour by using crontab:

0 * * * * cp /project/myfile /project/backups/backup_`/bin/date +%Y-%m-%d-%H`
0 * * * * cp /project/myfile /project/backups/backup_$(/bin/date +%Y-%m-%d-%H)

None of these lines are working. Instead I receive mails, complaining about “unexpected EOF while looking for matching “” \ “syntax error: unexpected end of file”.
Referring to the man pages (man 5 crontab), “%” are “newline characters” and needs to be escaped with backslash:

The “sixth” field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a new-
line or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file. Percent-
signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first
% will be sent to the command as standard input. There is no way to split a single command line onto multiple lines, like the
shell’s trailing “\”.

In other words, to get it working, add backslashes (\) in front of your “%”s and your fine:

0 * * * * cp /project/myfile /project/backups/backup_`/bin/date +\%Y-\%m-\%d-\%H`

Logitech QuickCam Messenger on Ubuntu 9.04 (Jaunty)

14. June 2009

Thanks to everyone helping me out, making this instruction better. Once again, this shall help you getting a Logitech QuickCam Messenger (ID: 046d:08f0) running on Linux Ubuntu 9.04 (Jaunty) using Skype. Please don’t waste any time posting instructions for other webcams. We don’t care!

To make sure, you got the right cam, plug it into your computer.
Check if your camera matches my ID by running:

lsusb | grep QuickCam

There should be something like this:

Bus 008 Device 003: ID 046d:08f0 Logitech, Inc. QuickCam Messenger

If your ID matches, please continue, otherwise you might be lucky and can start installing Gstfakevideo straight away. However this “Howto” was only tested for a QuickCam Messenger with the ID above. For other IDs please take a look here: https://wiki.ubuntu.com/SkypeWebCams

All you need before we start:

sudo apt-get install libgstreamer0.10-dev pkg-config subversion linux-headers-$(uname -r) build-essential

Remove the old quickcam_messenger module because it will not deliver the correct colors for our cam. If you do find a solution for this problem, please leave a comment! Thanks. Anyway removing the installed module:

sudo rmmod quickcam_messenger

To make sure it is not going to be loaded again we add the following line at the end of /etc/modprobe.d/blacklist.conf

blacklist quickcam_messenger

Download the new qcmessener module:

wget http://home.mag.cx/messenger/source/qc-usb-messenger-1.8.tar.gz
tar xzvf qc-usb-messenger-1.8.tar.gz
cd qc-usb-messenger-1.8

Apply this patch:

wget -v http://kuhrti.de/files/qc_2.6.28_patch.txt
patch -p0 < qc_2.6.28_patch.txt

Continue installing:

make
sudo make install
sudo insmod ./qcmessenger.ko

Ignore the “Kernel configuration is invalid.” errors.

Give it a test:

sudo qcset /dev/video0 compat=dblbuf
sudo gst-launch-0.10 v4lsrc device=/dev/video0 ! ffmpegcolorspace ! ximagesink

If every thing works go on and install Gstfakevideo:

svn checkout http://gstfakevideo.googlecode.com/svn/trunk/ gstfakevideo
cd gstfakevideo
make
sudo make install

Create a new file (i.e. in your home directory) called skype.sh and add these lines:

#!/bin/sh
gstfakevideo v4lsrc device=/dev/video1 ! ffmpegcolorspace

And run:

chmod a+x skype.sh

Now reload the module

sudo rmmod qcmessenger
sudo modprobe qcmessenger compatible=6 video_nr=1

Info: run

sudo modinfo qcmessenger

to view more options.

Create a new file /etc/modprobe.d/qcmessenger.conf and add:

options qcmessenger compatible=6 video_nr=1

This makes sure, that your webcam will always be /dev/video1 (as /dev/vidoe0 is needed for gstfakevideo) and uses “dblbuf” (correct colors).

Add your account to the “video” group:

sudo usermod -a -G video <YOUR USER NAME>

Finally fire up Skype by running skype.sh. That’s it!

Please leave a comment if you got some problems or want to give me feedback.

Here is a test image.

SSH: Connection closed.

13. June 2009

Wer viel mit SSH arbeitet, dem mag vielleicht aufgefallen sein, dass an manchen Standorten eine SSH Verbindung zu einem Server, nach einer gewissen inaktiven Zeit, einfach unterbrochen wird. Ursache dürfte in den meisten Fällen der örtliche Router sein, der nach X Sekunden die Verbindung einfriert.
Um dem entgegenzuwirken müssen wir einfach weiter Traffic senden. Dies kann auf zwei simple Arten geschehen.

Serverseitig
In der /etc/ssh/sshd_config folgende Zeile hinzufügen:

ClientAliveInterval 90

Restart des SSH Dienstes nicht vergessen.

Clientseitig
In der /etc/ssh/ssh_config folgende Zeile hinzufügen:

ServerAliveInterval 90

Persönlich favorisiere ich die serverseitige Variante, da das Verbindungsproblem sowohl client- also auch standortunabhängig heben lässt. Wem der Zugriff auf den Server verwehrt wird, dem bleibt halt nur die clientseitige Version.

Auto Login

16. January 2009

In some cases you might want your computer to automatically log in a user. There are a lot of tools or possibilities to do that but the lightest version I found so far, and I don’t think anybody can beat that, is just adding following line in your /etc/inittab:

1:12345:respawn:/sbin/mingetty –noclear –autologin <YOUR USER NAME> tty1

If it is not woking after a restart, make sure you installed mingetty.

Mehrere Dateien mit Prefix umbenennen

13. December 2008

Angenommen wir haben eine Reihe von Dateien, die alle mit einem Prefix in Form von ????_ (z.B 0234_, 1338_) beginnen, welches wir nun beseitigen wollen.
Die Lösung:

for i in ????_*; do x=`echo $i | cut -c 6- `; mv -v $i $x; done

Dazu erstellen wir eine Schleife in der wir die Variablen $i und $x definieren. $i sind alle Dateien, die ein Prefix der Form ????_* haben und $x ist nichts anders als $i (unsere Dateien) mit dem Unterschied, dass wir erst nach dem sechsten Zeichen anfangen zu lesen. Mit anderen Worten, wäre $i z.B 0323_MeineDatei.txt dann ist $x MeineDatei.txt.
Im letzten Schritt werden die Datein dann mit mv umbenannt.

So einfach kann das sein.

Logitech QuickCam Messenger on Linux using Skype

9. November 2008

Update: Ubuntu 9.04 Users klick here…

I am surprised how many people visit my site because their looking for a solution to get a Logitech QuickCam Messenger (046d:08f0) running on Linux using Skype

Since my last post seems to be a bit buggy for newer kernels, I updated my system to Debian (Lenny, 2.6.26-1-686) and gave it try.

All you need before we start:

apt-get install libgstreamer0.10-dev pkg-config subversion linux-headers-$(uname -r) build-essential

Plug in your webcam.
Remove the old quickcam_messenger module:

rmmod quickcam_messenger

To make sure it is not going to be loaded again we add

blacklist quickcam_messenger

at the end of /etc/modprobe.d/blacklist

Download the new qcmessener module:

wget http://home.mag.cx/messenger/source/qc-usb-messenger-1.8.tar.gz
tar xzvf qc-usb-messenger-1.8.tar.gz

Now if you are running kernel 2.6.26 or newer , it is necessary to patch some files.

wget http://bugs.gentoo.org/attachment.cgi?id=167504 -O patch.txt
patch -p0 < patch.txt

Continue installing:

cd qc-usb-messenger-1.8
make
make install
insmod ./qcmessenger.ko

Remember to be root when running make install

Give it a test:

qcset /dev/video0 compat=dblbuf
gst-launch-0.10 v4lsrc device=/dev/video0 ! ffmpegcolorspace ! ximagesink

If every thing works go on and install Gstfakevideo:

svn checkout http://gstfakevideo.googlecode.com/svn/trunk/ gstfakevideo
cd gstfakevideo
make
make install

Create a new file called skype.sh and add these lines:

#!/bin/sh
gstfakevideo v4lsrc device=/dev/video1 ! ffmpegcolorspace

And run:

chmod +x skype.sh

Now reload the module

rmmod qcmessenger
modprobe qcmessenger compatible=6 video_nr=1

Create a new file /etc/modprobe.d/qcmessenger and add:

options qcmessenger compatible=6 video_nr=1

This makes sure, that your webcam will always be /dev/video1 and uses “dblbuf”.

Finally fire up Skype by running skype.sh. That’s it!

Please leave a comment if you got some problems or want to give me feedback.

Update:
Here is a test image.

Wake On LAN

18. October 2008

You got Debian, a 3Com Corporation 3c905C-TX/TX-M [Tornado] (rev 74) Ethernet controller and a PC which needs to be started via LAN and it is not working?

I assume you change the BIOS settings already. All you need to do now, is to tell you Debian not to turn off your Ethernet controller while shutting down your system.

Create a new file /etc/modprobe.d/3c59x and add following line:

options 3c59x enable_wol=1

and run

update-initramfs -t -c -k all

Now you are done.
I use wakeonlan to start my computers.

Dateien rekursiv löschen

25. September 2008

Es kann vorkommen, dass ganze Verzeichnisse mit alten Backupdatein das Dateisystem unnötig aufblasen. Meinem Fall waren das Textdateien in From von index.php~. Die alle per Hand löschen? Auf gar keinen Fall:

find . -name *~ -exec rm -v {} \;

Dies eignet sich auch besonders gut, um die aus Windows stammende Thumbs.db aus Fotoalben zu löschen. Das würde dann so aussehen:

find . -name 'Thumbs.db' -exec rm -v {} \;

Wer über alte Subversion-Projekte stolpert und die .svn Ordner loswerden möchte, kann folgendes in seine Konsole eintippen:

find /projektverzeichnis -name .svn -type d -exec rm -rv {} \;

How you should use evdev for your Mouse

18. July 2008

If you are using a mouse with more than three buttons and a wheel on a Linux system, you probably heard about using evdev instead of the default mouse driver. Unfortunately, many of those tutorials on the net contain mistakes due to old parameters or manly by simply mixing up evdev and mouse options. However, it is quite easy to set it up.

If you want to use evdev just add (keep your Configured Mouse block) these lines to your xorg.conf

Section "InputDevice"
Identifier "MX518"
Driver "evdev"
Option "Device" "/dev/input/by-id/usb-Logitech_USB-PS.2_Optical_Mouse-event-mouse"
EndSection

And this line into ServerLayout:

InputDevice "MX518" "SendCoreEvents"

Just make sure you replace the device with the path to your mouse.
Otherwise you can run

find /dev/input/by-id/ -name "*event-mouse"

to get the right device. That’s it! Your done.

(more…)

Kleine Schrift in Firefox

30. April 2008

Nach einem Systemupgrade (~700 MB) und einem Reboot war es mir fast unmöglich sämtliche Systemtexte zu lesen, da die Schrift klein und unscharf war. Abhilfe verschafft folgender Code, der in einer neu erstellten /home/USER/.fonts.conf eingeführt wird:

#1
#2
#3
#4
#5
#6
#7
#8
#9
<?xml version='1.0' ?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target='font'>
<edit name='autohint' mode='assign'>
<bool>true</bool>
</edit>
</match>
</fontconfig>

Nach einem Restart von X waren zwar alle Fonts wieder auf Normalgröße, aber Firefox hatte da wohl noch so seine Probleme.
Dort öffnen wir about:config und setzen layout.css.dpi von -1 auf 0.

Was letzendlich zu dieser Verunstaltung führt, ist mir unbegreiflich.