Archive for the ‘Bash’ Category

PDF jonglage

November 27, 2009

Mehrere PDF’s zusammenfügen?

Das geht ganz einfach mit pdftk.

So habe ich z.B. für meinen Lebenslauf alle Zertifikate als PDF einzeln gescannt. Für den fertigen Lebenslauf kette ich alles zusammen in ein Dokument:

pdftk *.pdf cat output bewerbung.pdf

Vier Seiten auf eine? PDF um-formatieren für Handouts geht mit pdfnup aus dem Paket PDFJam, welches hilfreiche Scripts anbietet (hier gefunden).

pdfnup --nup 2x2 myfile.pdf

PDFJam enthält auch noch pdfjoin welches das gleiche macht wie oben und pdf90 zum rotieren.

Schnell und einfach, so haben wir es gerne!

Backup und Restore mit MySQL

Oktober 14, 2009

Für Leute mit Shell-Erfahrung, ohne Worte!

Einfach, schnell und effektiv 🙂

Backup

for i in `mysql -B -h $HOST -u $USER -p $PW $DATABASE -e "show tables"| tail -n +2`;
do
    echo "Dumping $i"
    mysqldump -h $HOST -u $USER -p $PW $DATABASE $i > $i.sql
done

Restore

for i in `ls *.sql`
do
    echo "Processing $i"
    mysql $DATABASE -h $HOST -u $USER -p $PW < $i
done

Colors in the Bash

September 10, 2009

Here is a script which shows how colors are used:

#!/bin/sh
############################################################
# Nico Golde <nico(at)ngolde.de> Homepage: http://www.ngolde.de
# Last change: Mon Feb 16 16:24:41 CET 2004
############################################################

for attr in 0 1 4 5 7 ; do
    echo "----------------------------------------------------------------"
    printf "ESC[%s;Foreground;Background - \n" $attr
    for fore in 30 31 32 33 34 35 36 37; do
        for back in 40 41 42 43 44 45 46 47; do
            printf '\033[%s;%s;%sm %02s;%02s  ' $attr $fore $back $fore $back
        done
    printf '\n'
    done
    printf '\033[0m'
done

Just run the script in your terminal and see the result.
The shown numbers can be used to color the background or foreground of output.

(more…)

In and Out

September 10, 2009

Standard Input

Ever wondered how to write a script that you can pipe stuff in? Here you go:

while read LINE;
do
    echo $LINE
done

(more…)

Bash Arguments

September 10, 2009

Basic stuff you’ll need if you write a script that uses arguments. Just try it to see what happens.

echo arglist: $*
echo amount: $#
echo scriptname: $0
echo arg1: $1
echo arg2: $2

Here’s an example how you can loop trough all arguments using $*.

for i in $*
do
    #will echo all the variable passed as parameters
    echo $i
done

Bash Loops

September 9, 2009

for-loop

The general syntax is like this:

#!/bin/bash
for i in $( ls ); do
  echo item: $i
done

(more…)