Dateiausgabe ohne Kommentar -und Leerzeilen

Bei langen Konfigurationsdateien kann es manchmal hilfreich sein, die Kommentarzeilen und Leerzeilen zu entfernen um eine übersichtliche „saubere“ Konfig-Datei zu erzeugen.

Das folgende Kommando gibt die Datei namens filename auf der Kommandozeile aus:

Will man direkt eine neue Datei erzeugen, so kann man den Output umleiten:

 

Mit sed sieht das Ganze dann so aus:

  • Ausgabe der Datei inputFile auf der Kommandozeile

  • Direktes Editieren der Datei filename ohne Ausgabe (Die Anführungszeichen für den -i Parameter können bei Linux entfallen)

Vorsicht! Fehlerhafte sed Expressions können die Datei beim inplace Editieren unbrauchbar machen. Wenn man sich nicht sicher ist, sollte man lieber ein Backup-Dateiendung beim Parameter -i nutzen.

Wenn die Kommentarzeichen in den Dateien keine Rauten sind, muss man die Zeichen in den Expressions entsprechend ersetzen.

Ubuntu Surfstation

For a public surfstation available for free we needed to have a system, that just simply always works. No user should be able to reset any configuration-settins, change the wallpaper, modify favorites or anything like that. The decision of the operating system was easy: Linux! 🙂

The needed tasks to install this system are the following:

– Download and install Ubuntu (the „Gnome Edition“) with all updates (there should be tons of howtos for this in the net)

– During the installation create a user that will be automatically logged in.

– Disable all keyboard-shortcuts in the system-settings dialogue.

– Install the following two addons in Firefox: BlockSite and OpenKiosk
In the OpenKiosk Adminscreen (can be started directly from Firefox) you can customize your „hardened“ Firefox. I personally set fullscreen mode, increased the reset interval to 3 minutes, enabled a 30 seconds warning before the reset and removed the Print button and zoom controls.

– Configure Firefox to start automatically when the user logs in.

– Create the file /etc/X11/xorg.conf with the following content. This disables the Ctrl+Alt+F1,Ctrl+Alt+F2, etc. shortcuts for switching through the gettys.


Section "ServerFlags"
Option "DontVTSwitch" "true"
EndSection

– Mount the root Filesystem readonly with the aufs Filesystem. This ensures that a reboot of the Surfstation/Terminal resets everything to default settings (although there shouldn’t be many changes besides the browser history) Here is a great Tutorial for that.

VMWare: Debian NICs don’t come up after removing and adding virtual network card

A long time has passed after the last post to this blog. But I’m still alive and today there will be another. 😉

Yesterday I stumbled upon some problems in our virtual infrastructure regarding the Debian Linux Servers. For several reasons (most important is a dedicated network for NFS) i needed to add another virtual network card to those servers. I also removed the existing card, because the type of that card was still „Flexible“ and I wanted to change that to „E1000“ anyway.

So in short: 1 card (Flexible) was removed, 2 cards (E1000) were added. Sounds easy, but it wasn’t! 🙁


SIOCSIFADDR: No such device
eth0: ERROR while getting interface flags: No such device
SIOCSIFADDR: No such device
SIOCSIFADDR: No such device
eth0: ERROR while getting interface flags: No such device
eth0: ERROR while getting interface flags: No such device

The interfaces don’t come up and i had no idea why!

After some investigation this issue seemed to be related to udev. The MAC address of the old NIC was still in the file /etc/udev/rules.d/z25_persistent-net.rules, but of course the MAC has changed after migrating to the new E1000 card.

The solution is to edit the above mentioned file and replace the wrong MAC address value(s) with the new ones.

After that the appropriate servies need to be restarted:


/etc/init.d/udev restart
/etc/init.d/networking restart

or in short:


reboot

That’s it! 🙂

Connecting to MSSQL databases with PHP from Linux

I needed to get some data from existing MSSQL databases with PHP. Connecting to such servers is a bit more tricky than mysql, because the mssql extension from php needs also a correctly configured TDS installation. But we’re lucky, there is an opensource implementation of the tds protocoll called FreeTDS. If you don’t want to use tds you can also try to get it to work with ODBC, but ODBC is very slow and that’s why it’s also not part of this blog post.

So here we go…

1. Installation of FreeTDS:
– Get the latest release of FreeTDS from here: http://freetds.org/ (the time i write this it’s 0.82)
– Extract and compile it:

tar xzvf freetds-stable.tgz
cd freetds-0.82/
./configure --prefix=/opt/freetds --with-tdsver=8.0
make
make install

– Edit /opt/freetds/etc/freetds.conf and add your MSSQL server like this:

[MSSQLserver]
host = hostname or ip
port = 1433
tds version = 8.0

MSSQLserver is used in your php code afterwards, so it might be a good idea to think of an appropriate name.

2. Installation of PHP
– Get the latest release of PHP from here: http://www.php.net/downloads.php
– Extract and compile it:

tar xjvf php-5.3.0.tar.bz2
cd php-5.3.0/
./configure --prefix=/opt/php --with-apxs2 --with-mssql=/opt/freetds
make
make install

This is a very limited version of PHP just to show the required options in order to get PHP to work with MSSQL. If you have additional requirements like mysql-support or gd processing stuff you need to add those options to the configure call.

After that you need to tell Apache to load the appropriate module (libphp5.so). Add the following line to your httpd.conf file:

LoadModule php5_module /usr/lib/httpd/modules/libphp5.so

The location of the module may vary.

If everything went fine, you can now start to ‚CRUD‘ your MSSQL data. Have fun…

Tunneling Rsync through SSH for ABS updates

As I told on my previous post I’m currently using Archlinux here at work. Archlinux has beside it’s ’normal‘ package management system pacman (similar to apt-get) a ports-like application-repository called the ‚Arch Build System‘ (ABS).

In order to use the ABS software repository and to be able to install software from it, you need to sync the whole package tree to your local disk. This doesn’t contain the full packages with all tarballs and stuff – it’s only some Meta-information. The necessary files needed for a package installation will be downloaded on request when installing the software.

Updating the ABS-tree is being done by rsync. The problem is that I don’t have the possibility to connect to the internet by something other the http(s) and ssh, but I haven’t found a solution yet to tell abs to use rsync over ssh for this step.

So my workaround for this is the following:

– Tunnel the rsync requests to the Arch servers via ssh (this needs root priviledges)

ssh -l johndoe -L 873:rsync.archlinux.org:873 yoursshserver.cooldomain.com

– Edit /etc/abs.conf and replace the value for SYNCSERVER with ‚localhost‘

– Run abs

It’s working very fine, but I have to admit that you need a ssh-server to connect to in the internet or at least a linux-box (of course any other ssh-able server will fit too) accesible via dyndns.

Speeding up Arch Linux

Currently I’m using Arch Linux on my desktop-machine at work. As I’m still at the evaluation phase i read trough some forums, wikis and blogs about Arch Linux.
One very interesting article I found was this one: http://www.cywhale.de/arch-linux-optimieren-booten-in-16-sekunden/
It describes how the booting time can be speeded up with some nice tricks. I did not all steps described there, but only the few changes i made saved me 19 seconds and my arch-machine now boots to the KDE logon-screen in 13 seconds.

Before the optimization:

bootchart_slow

After:

bootchart

200 days Uptime!

Today I received an email from the uptime daemon on my machine:

Monitoring of max open files in a vserver

Running services on a virtual server sometimes causes problems. I often faced such porblems by reaching the maximum amount of open files. In that case applications like Apache or Postfix fill up their logs with lines like this:

„Too many open files in system“

I wanted to be able to monitor the amount of open files on my server (OpenVZ/ Virtuozzo) to easily see when there were and also when there might be problems. I decided to give Munin a try. Installation and basic Configuration was really simple and what I like very much is that custom plugins can be written very quickly with basic knowlegde of bash or perl.

Attached is my munin plugin. Just copy it to /etc/munin/plugins (in the default installation of munin) and rename it to vserver_open_files. Also add following lines to the file /etc/munin/plugin-conf.d/munin-node, because this plugin needs to run with root privileges.

[vserver_open_files] user root

vserver_open_files-day

Here is the link: https://www.schmalenegger.com/files/vserver_open_files.sh

using msmtp with mutt

Since a few days ago i only used mutt directly on my server where the fully-loaded and configured postfix was running. The setup always worked and still works fine, but i wanted to use mutt also on a different machine and still be able to send mail via smtp through my postfix on the server.

As I don’t want to use postfix for this simple „mail-forwarding“ job, i googled a bit through the internet and found msmtp.

Installation and configuration is quite simple. msmtp is available via package-management on most linux distributions and it only needs on single configuration-file to get it running.

Simple paste the following content (adapted to your needs of course) to .msmtprc in your home folder:


account default
host mail.yourserver.com
auth on
user johndoe
password verysecret

What’s now left to do is to tell mutt to use msmtp instead of /usr/sbin/sendmail.
This is done via the following line in your .muttrc:


# use msmtp
set sendmail="/usr/bin/msmtp"

That’s it.

monkey HTTP Server debianized

The „“famous“ monkey http server has made it to the Debian Sid repository.
You can find it’s website here: http://packages.debian.org/sid/monkey

Thanks to Romain Beauxis from rastageeks.org and of course Eduardo Silva – the upstream developer.