Monthly Archives: March 2016

Shell scripting

There are many shells available like bash, dash, ash, csh. Bash (Bourne Again Shell) is the richest with features but at the same time also big (combiled image in my system about 1 MB) and sometimes also slow. Therefore Debian and many derivatives (Ubuntu, Mint, …) use dash as the startup shell. Dash is smaller (compiled image size about 0.12 MB in my Ubuntu based system).

If you want to see the source code of the shell you can get it in Debian and derivatives with commands (following gets the source of bash)

Remember that you should not use sudo when getting the source code.

Next to the scripting itself. The scripts can be driven from the command line like

You can make a very simple Hello World script with editor and save it as test.sh

And you can run it on the command line

By adding to the script #!/bin/bash #!/bin/bash

you can call the script directly by giving the execute rights with chmod

Variables can be defined like variable_name=”some text” or in the case of numbers or single words variable=1 (without quotation marks). There are some predefined variables like PWD which means current working directory. When you are using the variables you have to use $-sign before the variable. Example

prints your current working directory.

Conditions. If then -structure.The test will be made inside of brackets [ ]. The structure is ended with fi.

Below we will test if some port is open with a netcat program. nc – z localhost 22 test if the port is open. The return value is stored in $? variable. If it is open the return value is 0 otherwise something else.

For-loop. We test now if some port is open. This is basically a very simple netstat.

It is usually a very good habit to try to keep the shell scripts as portable as possible between different shells. There is a command line tool called checkbashism available to chech if you have used something that would work only on bash.

Some topics to cover

  • If you want to read variables you can used read-function.

There are books on shell scripting

Installing the latest WordPress on Debian 8 (Jessie) with automatic updates

There are two possibilities to install WordPress on Debian. Either it is possible to use the Debian apt-get install method or install direct the latest version from WordPress.org site. While Debian version is pretty old and some functionality and interoperability will be lost with the older versions (like using some website themes), I prefer installing the latest version.

WordPress needs a webserver, a database and a PHP-interpreter (PHP = Hypertext Preprocessor). I use Apache as a web-server, MySQL as a database and PHP5 interpreter. Some additional components for network communication (php5-curl) and image manipulation (php5-gd) are proposed as well. In Debian 8 Jessie they can be installed with a command on command line as root

You need to define password for the MySQL root-user. This password is needed when you make a database for the WordPress. It can be made either with a helper application like phpMyAdmin or direct with the MySQL-client. I use the commandline client.

in the MySQL-client you will create for the wordpress a database called wordpressDB and a user called wordpress with a password (replace password with your own).

Now you can download WordPress and install it by uncompressing the file.

Now you can edit the WordPress configuration file

by adding the right database and user name and the password.

Then you can allow the automatic core updates by adding to wp-config.php the following line

Now you can configure you web-server by adding following configure file to /etc/apache2/sites-available/myblog.com

You need to have mod_rewrite and mod_vhost_alias modules enabled by giving on a command line

Finally you can enable your website

After that you can configure your site by going with the web-browser to the address of your blog (like www.myblog.com).

Adding code snippets to WordPress post

Probably the easiest way to add nice code lines to a post is to use some plug-in like Crayon Syntax Highlighter or SyntaxHighlighter Evolved.

codehighlighterMy favourite is Crayon Syntax Highlighter. Good thing is that there are lots of options available. Bad thing is, that there are for the first time too many options available. It means there is a bit of learning curve. You have to play a bit with it.

The code is inserted (copy pasted) in a editing window.  Here is an example of Hello World in c-language.

The second choice called SyntaxHighlighter Evolved is used by writing the tags direct with WordPress text editor. You should not use Visual mode editing, while it might remove the code tags. Remember that code begins with [ code ]-tag do not use < code > -tags!. You can add some variables like language. The code

will produce

#include
main( )
{
printf("hello, world\n");
}