Archive for March, 2007

Argument List too Long – Part 2

Wednesday, March 14th, 2007

So, jetzt zum nächsten Problem. Sie haben ein Verzeichniss das hunderte oder tausende von bildern enthält. Von einer Webcam z.B.

Sie wollen alle Bilder von einem bestimmtem Datum in ein ZIP packen.

Der Trick mit dem grep vom anderen Post bringt sie da nicht wirklich weiter. Richtig. Also nutzen wir etwas anderes. Wie wäre es mit find. Also einfach mal die code Zeile angeben und ich breche sie dann in Stücke. Zur info, unser Beispiel findet am 13ten statt und wir wollen Bilder vom 10ten.

find . -name "*.jpg" -daystart -mtime 4 -exec cp -p {} ../archive_2007-03-09 \;

1. find – sucht uns alle Dateien die im namen “*.jpg” drin haben raus. Dass heisst wir bekommen eine saubere Liste mit den Namen der Bilder.

2. Mit daystart sagen wir dass unser Zählen / Datums / Zeitangabe vom Anfang des Tages statt findet, also von 0 Uhr.

3. mtime 3 – sagt aus das es vor 3 Tagen war

4. exec cp – wir führen einen copy Befehl aus und die {} sind die Platzhalter für jedes gefundene Item. Mit dem “-p” bewirken wir das unsere Datums und Zeit Angaben der Datei beibehalten werden.

5. und das Ganze stopfen wir in irgend einen Ordner

- WICHTIG: Am ender der Zeile befindet sich ein lehr Zeichen, ein Backslash und ein Strichpunkt. Dies muss so sein damit “exec” weiss das hier ende der Fahnenstange ist, da man ja auch für exec mehrere Befehle an einander ketten könnte.

Jetzt kann man einfach den Ordner schnappen und in ein zip stopfen.

Ja man könnte das Ganze gleich in ein zip stopfen, muss aber beachten das für jedes Item das gefunden wird exec aufgerufen wir und somit zip gestartet, das archiv geöffnet, die datei reingelegt und das zip wieder geschlossen wird. Hat man also viel Zeit kann man es direkt in ein zip werfen. Will man schneller vorgehen macht man lieber den zwischenschirtt mit dem copy Befehl.

Survey / Umfrage leicht gemacht

Wednesday, March 14th, 2007

Hab schon länger mal was für Umfragen gesucht … http://www.phpsurveyor.org/ … sieht richtig gut aus.

Argument list too long

Thursday, March 8th, 2007

Well, if that is the error you are getting on your Linux box then it looks like you have just got too many things that you are trying to run through the mill in your shell.

I stumbled accross this one

Basic reason being how the shell handles wildcards. If the list gets too long, the above error appears. So it is not the program running into trouble, but your shell.

If you are just using “ls” you can do this simple trick:

ls | grep "\.txt"

Here you are not using any wildcards. No expansion happening. The following grep command is picking the files with the extensions for you.

If you don’t just want to see the files, but use the list the above will not get you too far. Instead we use “xargs”. This nice little tool reads a list of file names and splits them into chewable bits.

If for example all files with the ending “.txt” are to be stuffed into a tar archive, you would use the following line:

ls | grep "\.txt" | xargs tar -rf TextArchiv.tar

So, ls will list all files, grep will return all files with the “.txt” ending and xargs splits the list into a bunch of blocks and calls up the tar command with each block of data. The “-r” is what ensures that the blocks are joined into one in the archive.

So, hope this helps someone.

Check mailserver with telnet

Thursday, March 8th, 2007

Well, every once in a while you need to do this. And what was the command again ?? How did that work exactly ?? As my memory is getting overloaded once in a while I decided to post my favorite Link right here, that way I know where it is next time I need it.

http://www.simplescripts.de/smtp-check-port-25-telnet-command.htm

That’s the page I use for a quick look up.