Categories
SAP

Full-Text Search for SAP-ABAP reports

The SAP standard report RPR_ABAP_SOURCE_SCAN allows you to search all your ABAP sources for specified keywords or a phrase. You can select reports or packages to search in and choose whether to search commentary, too.

It’s not only handy when you need to find that special line of code, but also if you want to see the usage of certain statements. For example, you can see which and how many reports use “UPDATE”, “DELETE”, etc to update the database.

Categories
Shell

Finding files older than date on Linux

The find command is very powerful when it comes to searching for files, yet it’s missing a way to find files older than a certain date. There is the -mtime parameter that allows you to find files modified in the last x days but sometimes you need to specify dates, like “all files from 2008 and 2009”. This can be done using the “newer”-parameter and “touch”. It’s probably not the most elegant solution but it works fine and is easy to understand.

Basically, you just use touch to create special files that specify the timeframe. For example to find files older than 2009 you would create a file as follows:

touch -d'2009-01-01 00:00:00' end

This creates a file “end” with the specified timestamp that then can be used with find:
find /var/backup/ ! -newer end
As said before, you can also use this to specify a timeframe by creating a second file …

touch -d'2006-01-01 00:00:00' start

… and using it with the find command:

find /var/backup/ ! -newer end -newer start

This would match all files from 2006, 2007 and 2008.
Of course the date can be modified to match pretty much any timeframe necessary.

Additionally you may filter certain filetypes that you want or don’t want to be matched. The following command:

find /var/backup/ ! -newer end -newer start -iname '*.jpg'

will find every Jpeg file in the specified timeframe. iname works as case insensitive, whereas the corresponding -name is case sensitive.
It’s also possible to filter multiple names with the -o parameter. An example would be as follows:

find /var/backup/ ! -newer end \( -iname '*.mkv' -o -iname '*.avi' \)

This finds all files in /var/backup, that are not newer than the “end”-file and end to either .mkv or .avi (or .AVI or .mKv …).
There are plenty more options to define what files you want to be found but these examples should suffice to show the basic usage.

Now that we’ve matched our files it’s time to do something with them. That’s where -exec enters the stage.
Exec allows you to execute a single statement for every matched file. Of course it could also invoke a script but to keep it simple I’m only going to use commands like rm, ls or zip.
A good start is always to list the files that have been matched using ls.

find /var/backup/ ! -newer end -newer start -exec ls -la '{}' \;

The curly braces will be replaced with the filename that has been matched and the command will be executed. This is pretty easy and straight-forward. You can also use it with rm or bzip or whatever you want.
However, if you’re dealing with a LOT of files this will run very slow, since the command is invoked for every single file. This might not be a problem when compressing files, since the compression is taking most of the time anyway but if you’re just listing or removing files, the overhead from spawning a new process for every execution becomes substantial.

To speed things up there’s another syntax with a “+” at the end of the line:

find /var/backup/ ! -newer end -newer start -exec ls -la '{}' +

This appends the filenames to the end of the line until the maximum length has been reached. That way one process of rm may delete several files, reducing the overhead and speeding up the overall process. The difference is probably insiginificant when processsing 10 files but when dealing with several hundred or thousand matches you’ll definitely notice a difference.

An alternative to this syntax is using xargs. Xargs takes everything from standard input and splits it up into smaller lists so the maximum number of arguments for a single command is not reached. Example:

find /var/backup/ ! -newer end -print0 | xargs -0 mv {} /var/backup/archive

As with exec, the curly braces define where the argument will be inserted. The parameter print0 prints every result and additionally replaces whitespaces with zeroes so filenames with spaces will work just fine. The corresponding -0 in xarg allows it to expect the right format.

This is just a simple alternative to exec, you probably won’t notice any difference to it when using the “+”-syntax.

Categories
Siri

Siri Proxy mit Bind

Seit langem mal wieder ein neuer Artikel, diesmal zum Thema SiriProxy.
Man findet wirklich genug Anleitungen im Netz, die die Einrichtung von SiriProxy sehr ausführlich, oft sogar mit Videos, beschreiben (z.b. hier, hier oder hier). Sobald es allerdings darüber hinausgeht und man ein paar Sonderwünsche hat, muss man schon genauer suchen oder selbst Hand anlegen.
Zwei dieser Sonderwünsche, die bei mir auftauchten, möchte ich im folgenden kurz erläutern.

Zum Einen läuft in meinem Netzwerk bereits ein DNS-Server, genau gesagt bind9. In den Tutorials zu SiriProxy wird allerdings oft nur die Konfiguration und Installation von dnsmasq beschrieben, die in diesem Fall nicht sehr hilfreich ist. Zwar gibt es auch einen Konfigurationshinweis für Bind, die Beschreibung fällt jedoch sehr karg aus. Das soll die folgende Anleitung ausbessern und baut dafür auf der Datei auf.

Ausgangslage ist hier ein Ubuntu 11.10 mit einem installierten und konfigurierten bind9-DNS-Server.

Zunächst gilt es die Konfiguration des DNS zu öffnen. Diese liegt normalerweise in der Datei /etc/bind/named.conf.local

sudo nano /etc/bind/named.conf.local
Natürlich könnt ihr den Editor beliebig wählen. Dort sucht ihr die Stelle, an der die bisherigen Zonen konfiguriert sind und fügt folgendes ein:

zone "guzzoni.apple.com" {
type master;
file "/etc/bind/zones/guzzoni.apple.com.db";
};

Anschließend wird die Datei gespeichert und in das Unterverzeichnis “zones” gewechselt. Sollten die bisherigen Zonendateien an einer anderen Stelle liegen, kann auch dorthin gewechselt werden werden. Allerdings muss dann auch in der named.local.conf der Pfad entsprechend angepasst werden.

cd /etc/bind/zones/

Hierhin kann man direkt die Zonendatei von Github laden oder eine neue Datei mit gleichem Namen anlegen (guzzoni.apple.com.db) und folgenden Inhalt hineinkopieren:


;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA ns.guzzoni.apple.com. host.guzzoni.apple.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.guzzoni.apple.com.
guzzoni.apple.com. IN A 172.16.1.99
ns IN A 172.16.1.99

Wichtig ist dabei, dass alle Zeilen mit führenden “//” entfernt werden, da diese von bind nicht als Kommentar interpretiert werden. Weiterhin muss die IP 172.16.1.99 an allen Stellen ausgetauscht werden gegen die IP, unter der der DNS-Server im Netzwerk selbst erreichbar ist. In meinem Fall wäre das die 192.168.178.31.
Zu beachten ist weiterhin, dass der Server der konfiguriert wird selbst nicht den selbst angebotenen DNS-Dienst nutzen darf, da SiriProxy sonst gar nicht mit Apple kommunizieren kann.

Damit ist die Konfiguration abgeschlossenund nach einem Neustart des DNS-Dienstes kann bind mit SiriProxy genutzt werden.

sudo /etc/init.d/bind restart

Der nächste “Sonderwunsch” wird in einem folgenden Artikel behandelt, dort geht es dann um das automatische Starten von SiriProxy beim Systemstart und nach Abstürzen.

–Powl

Categories
Server

FTP einrichten unter Debian

Um FTP unter Debian einzurichten sollte man sich erstmal einen FTP Client installieren, in diesem Fall Proftpd:

sudo apt-get install proftpd

Anschließend kann man die ersten Einstellungen vornehmen, indem man /etc/proftpd/proftpd.conf mit dem Editor seiner Wahl öffnet und am Ende

<Global>
RequireValidShell off
</Global>

DefaultRoot ~ ftpuser

<Limit LOGIN>
DenyGroup !ftpuser
</Limit>

hinzufügt.

Der erste Befehl ermöglicht es, für die FTP-Benutzer die Shell zu deaktivieren. Der zweite Befehl sperrt die User in ihrem Home-Directory ein und der letzte beschränkt den FTP-Zugriff auf User in der Gruppe ftpuser.
Nun kann man die Datei speichern und den Dienst neu starten, um die Änderungen zu übernehmen:

sudo /etc/init.d/proftpd restart

Anschließend können wir die Gruppe für die FTP-Benutzer anlegen:

sudo addgroup ftpuser

Und diese mit dem ersten FTP-Nutzer füllen:

sudo useradd ftpbenutzer -s /bin/false -d /var/www

Das HomeDir /var/www ist dann das Verzeichnis auf das man per FTP zugreifen kann. Durch -s /bin/false deaktivieren wir die Shell, damit der Nutzer auch wirklich nur FTP nutzen kann.

Jetzt muss nur noch der Nutzer in die passende Gruppe hinzugefügt werden:

sudo useradd ftpbenutzer ftpuser

Nun kann man sich mit dem Nutzer per FTP einloggen.

Categories
Server

WordPress und Debian

Wenn man auf einem Debian System WordPress installieren möchte, sollte man dies besser nicht über “apt-get install wordpress” tun, da die Version aus der Paketverwaltung meist stark verwaltet ist (derzeit v2.0 gegen die aktuellste 2.9.2). Am besten man lädt stets die aktuelle Version von der WordPress-Downloadseite.

Eine detaillierte Anleitung zur Installation und Konfiguration von WordPress gibt es beispielsweise hier.

Categories
Server

PHP Fehler

Wenn eine php-Seite (in diesem Fall ein phpBB) folgende Fehler bringt:

Warning: Module ‘gd’ already loaded in Unknown on line 0

und

in file /includes/functions.php on line 4183: Cannot modify header information – headers already sent by (output started at /common.php:181)

wird ein Modul (in diesem Fall gd) mehrfach geladen. Um das zu korrigieren muss bei den PHP Extensions oder direkt beim Apache/Conf.d ein Aufruf dieses Moduls auskommentiert werden. Solange das Modul einmal geladen wurde steht es auch komplett zur Verfügung.

Die zweite Fehlermeldung, die gern auch mehrfach auftaucht ist eine Folge des ersten Fehlers. PHP kann den Header der Seite nur modifizieren, solange noch nichts auf der Seite ausgegeben wurde. Da aber in diesem Fall die Fehlermeldung zu gd ausgegeben wurde, kann der Header nicht mehr modifiziert werden und die Ausführung kommt zum Stehen.
Diese Meldung ist also meist Folge von anderen Problemen oder Programmierfehlern.