preload
Mrz 02

Due to the fact I got in touch with maven2 and I think that maven2 is very helpful will give a short introduction. Bigger projects normally have a more complex configuration but I will start from the scratch.

Maven will create a kind of project sceleton with the following command

1
mvn archetype:create -DgroupId=info.sobek.testapp -DartifactId=testapp

If you work with e.g. eclipse, you can create the project files for eclipse:

1
mvn eclipse:eclipse

Now you can import it into eclipse with “import into existing workspace” option of eclipse.

Maven will normally copy the created so called “artifacts” into your local maven repository. Normally located under your home dir and then .m2

When you program depends on several jars and these dependencies are defined in the pom.xml, then maven will copy the jars in their specific version into the local maven repository. This is very helpful because you can simply build your project with another newer or older version of your dependent jar-file.

How to create multi-module projects will be explained in another episode.

Tagged with:
Dez 20

If you want to download a file with curl type the following code into bash:

1
curl -O http://www.url.de/file.html

-O means to output to a file and not to stdout, normally the screen.

What if you need to resume a download of a big file?

1
curl -C - -O http://www.url.de/file.html

With -C – you continue downloading the current file. If is important to write -C -. Don’t forget the -

You can also set a referrer and the user agent.

1
curl -C - -O -A http://www.url.de -e "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6" http://www.url.de/file.html

With -A you can set the referrer and -e sets the user agent.

Pretty helpful.

Tagged with:
Dez 08

To detach from an actual session press

1
Ctrl+a d

Reattach with

1
screen  -r

To list the actual detached sessions:

1
screen  -list

You will see something like:

1
2
4840.pts-3.localhost  (Detached)
4628.pts-1.localhost (Detached)

Reattach it with:

1
screen  -r 4840.pts-3.localhost

To share a session with another user you have to ensure some steps.

Set the screen binary setuid root:

1
chmod  +s /usr/bin/screen

Login as root and start a screen session and name it:

1
screen -S sessionName

Enable multi-user access function by pressing Ctrl+a then :multiuser on (to type “:”, press “shift+;”)
Grant permissions to the second user by pressing Ctrl+a: acladd username, where username is the Unix user for the second user.

1
screen  -x root/sessionName

Activate logging with:

1
Ctrl+a H

A file in your home directory will be created. Something like $HOME/screenlog.1

Type exit to exit screen.

Nov 25

To replace a string in all files inside a folder you can create a bash file:

1
vi replace.sh

Put inside this file:

1
2
3
4
5
6
#!/bin/bash
for file in $(ls -1);
do
sed 's/me/you/g' $file > /tmp/dummy.txt;
mv /tmp/dummy.txt $file;
done

Save it and make it executeable (chmod 777 replace.sh)

In this case the string “me” will be replace with “you” in all files of the actual folder and the files will be overridden.
Another example
Your want to replace the tag <b> with <strong> in all files inside a special folder. Further you want to backup the original files with suffix .old and the new files will be overridden.
Simply type on the console:
1
2
3
4
5
for file in $(ls -1);
do
mv $file $file.old
sed 's/&lt;b&gt;/&lt;strong&gt;/g' $file.old &gt;  $file;
done
You can modify the script(s). Maybe by adding parameters etc.

Another option is to use sed with -i command or direct editing:

1
2
3
4
for file in $(ls -1);
do
sed -i 's/text_to_replace/text_replacement/g' $file
done
Tagged with:
Nov 19

When switching from Mac to Linux and vice versa, I always have to think a bit about how to use the command top and sort by CPU.

With Linux it is

top

and then press

shift+p

Mac:

top -o cpu

I hope I can remember this :-)

Tagged with:
Nov 18

The situation is as follows. You want to search recursive for a text pattern inside of each files in the directory /var/www/vhosts. Take e.g. the pattern ‘DataStructure’.

Normally you would think about the find-command and executing another command but grep itself can do the job.

grep -RHl -e ‘DataStructure’ /srv/www/vhosts

This command lists all filenames containing the text ‘DataStructure’

Tagged with:
Feb 29

Möchte man mit scp kopieren so ist das generell kein Problem:

scp *.java user@servername.de:/home/user/

Läuft ssh über einen anderen Port, so ist das auch kein Problem:

scp -P 12345 *.java user@servername.de:/home/user/

Beachte: Bei ssh muss man ein kleines -p für die Angabe des Ports benutzen, bei scp muss dies ein große -P sein.

Soweit so gut und auch alles von Linux bekannt also völlig identisch.

Ich verbinde mit immer über ein Key-File:

ssh-add myprivatekeyfile

Anschließend muss man seine Passphrase eingeben. Befindet sich der Publikkey nun auf dem zu verbindenen Server in der authorized_keys, so kann man jetzt ohne Passwort mit dem Server per ssh verbinden.

So füge ich die Datei in die authorized_keys ein:

cat mypublickey >> ~/.ssh/authorized_keys

Damit wird der Inhalt des Public Keys in die Datei angefügt.

Aber zurück zum eigentlichen Thema. Ich konnte auf einen bestimmten Server nicht kopieren und war erst völlig ratlos. Nach längerer Analyse hab ich festgestellt, dass in der .bashrc-Datei, also die Datei die bei Login eines Users aufgerufen wird, der Inhalt einer Datei mittels cat ausgegeben wird. So eine Art Begrüssung. Diese Art von Begrüssung unterbindet den Verbindungs- und Kopiervorgang.

Also: Keine Ausgaben in der .bashrc, sonst hat man Probleme beim Kopieren mit scp!!!

Tagged with: