Blog Archives

Count all folders recursively

   ls -lR | grep ^d | wc -l

ls -lR gets a long format of all files and directories of a given folder. Every line which contains a directory starts with d as the first character. So grep ^d filters all such lines (^ is for Beginning-Of-Line). wc -l counts the Newline characters in a given file or stdin. Because every line contains a single directory entry and every line ends with a newline character, you will get the number of the directories.

Using tcpdump to check network traffic


tcpdump -nnvvS host <ip-address>

To look into the data packet add the -X switch:


tcpdump -nnvvXS host <ip-address>

Convert DVDs

A nice tutorial in German is available on http://www.selflinux.org/selflinux/html/dvd-rippen.html.

Use SSH keys

To access an SSH server you should always use keys instead of simple passwords. Generate your keypair with PuttyGen and save your private and public key part. On Windows you can use the private part with PageAnt to provide access to the SSH server without entering a passphrase. On the SSH server store your public part within the .ssh/authorized_keys file. But don’t use the Putty-generated public part, you have to copy and paste the OpenSSH format of the public key from the PuttyGen window.

If you need your private key on a Linux client to access the SSH server, you cannot use the Putty-generated private part. You will also need an OpenSSH format. This format you can export with the menu Conversions -> Export OpenSSH key. Store your OpenSSH key as id_rsa or id_dsa file and put it into the .ssh folder of the user. Both files will be used by the SSH client (the possible file names you can find on /etc/ssh/ssh_config as IdentityFile property). If you cannot use these file names, you can also store the private key with another name, but you have to define a config section for the SSH server in ~/.ssh/config:


#
# default:
# .ssh/identity
# .ssh/id_rsa
# .ssh/id_dsa
#
host name_ssh_server
Hostname full-qualified.ssh.server.name
Port 22
IdentityFile ~/.ssh/you_own_private_key_name
ForwardX11 no

You can now access the server “name_ssh_server” with

ssh username@name_ssh_server

which will use “full-qualified.ssh.server.name” on port 22. The private key file is accessible on ~/.ssh/you_own_private_key_name (file permissions 600!) and should match with an authorized public key on the SSH server.

A two way sync between Git and SVN

  • Create a GIT repository on GitHub.com.
  • Create a local repository from the GitHub repository

Use your SSH-Key (uploaded to GitHub.com)!

$ git clone git@github.com:witchi/PHP-SQL-Parser.git

  • switch to the new repository directory
  • Create a SVN tracking branch, which contains all the SVN changes


$ cd PHP-SQL-Parser
$ git branch --no-track svnsync
$ git checkout svnsync
$ git svn init -s https://php-sql-parser.googlecode.com/svn

  • write a file which contains all SVN authors and store it as svn-authors.txt into the Git repository directory
  • fetch all revisions from SVN
  • set the HEAD of the svnsync GIT branch to the latest SVN revision


phosco@gmx.de = André Rothe <phosco@gmx.de>
greenlion = Justin Swanhart <greenlion@gmail.com>
greenlion@gmail.com = Justin Swanhart <greenlion@gmail.com>
Justin Swanhart = Justin Swanhart <greenlion@gmail.com>
(no author) = Justin Swanhart <greenlion@gmail.com>


$ git svn fetch -A svn-authors.txt
$ git reset --hard remotes/trunk

Merge changes from SVN into Git

  • go to the svnsync branch
  • get all the new revisions from the SVN repository
  • go to the master branch (Git)
  • merge all changes from svnsync into the master
  • use meld to solve merge conflicts
  • upload all changes to the GitHub repository


$ git checkout svnsync
$ git svn rebase -A svn-authors.txt
$ git checkout master
$ git merge svnsync
$ git mergetool
$ git push origin master

Merge changes from Git into SVN

  • go to the master branch of Git
  • get all changes from the Github repository
  • go to the svnsync branch
  • get all new revisions from the SVN
  • merge all Git changes from master into the svnsync branch (without fast-forward, it creates a new commit point)
  • use meld to solve merge conflicts
  • commit the changes into svnsync branch (local)
  • commit the changes to the SVN repository server (remote)


$ git checkout master
$ git pull origin master
$ git checkout svnsync
$ git svn rebase -A svn-authors.txt
$ git merge --no-ff master
$ git mergetool
$ git commit
$ git svn dcommit

First steps with Git

To set some important configuration properties for Git use the following commands:


$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
$ git config --global merge.tool meld

The properties are set for all repositories on the current machine.

PHP_CodeSniffer standards

Look into /usr/share/php5/PEAR/PHP/CodeSniffer/Standards

All sub-folders there can be used as standard name:


phpcs --standard=PEAR test.php
phpcs --standard=Zend test.php

Find all used IP adresses within a subnet

If your local computers allow a ping, you can simply execute:


nmap -sP 192.168.x.*

where x is the subnet number (1 <= x <= 254). You will get a list of all hosts, their IP addresses and their MAC addresses. That is really cool for DHCP networks, where you don't know, which IP addresses are already been used.

Set the localtime on a Linux system

cd /etc

Set the timezone of your server location:

ln -sf /usr/share/zoneinfo/Europe/Berlin localtime

Check the new settings with:

date

If you have set the hardware clock with an UTC timestamp, the date command will calculate the correct time offset using the localtime settings (including daylight save time switch).

HTPP -> HTTP redirect on Glassfish 3.1.2.2

Execute this on your Glassfish machine:

###
### HttpToHttpsRedirectOnDifferentPort
###
asadmin create-protocol --securityenabled=false http-redirect
asadmin create-http-redirect --redirect-port 443 --secure-redirect true http-redirect
asadmin create-protocol --securityenabled=false http-redirect-base
asadmin create-protocol-finder --protocol http-redirect-base --target-protocol http-listener-2 --classname com.sun.grizzly.config.HttpProtocolFinder https-finder
asadmin create-protocol-finder --protocol http-redirect-base --target-protocol http-redirect --classname com.sun.grizzly.config.HttpProtocolFinder http-redirect
asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol=http-redirect-base