Manually executing a logfile rotation using logrotate

If you change some parameters in /etc/logrotate.conf or /etc/logrotate.d/* the most common way to use the new configuration is to call logrotate like:

logrotate /etc/logrotate.conf

That way will read the whole configuration of logrotate using parameters like minsize, age and so on.

But you can force logrotate to ignore those parameters so the rotation will happen even if the size is smaller than minsize (minsize as an example)

Simply call logrotate as seen from above with the -f parameter:

logrotate -f /etc/logrotate.conf

How to find out the used ip’s of a linux-system

The primary tool for this job was called ifconfig. This tool shows the IP addresses of all available network adapters. So regardless of whether it is an ethernet interface or a wireless adapter (of course there are much more types of network connections)

However, ifconfig should no longer be used at the present time will. Above all, in times of IPSec, ifconfig won’t correctly display all available interfaces.

The successor of ifconfig is simply called ip. The ip command shows not only the IP addresses. To give a similar output as ifconfig get used to ip with the following parameters:

ip addr show

The command from above will produce the following (or similar) output:

root@xxx:~# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group
default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP
group default qlen 1000
    link/ether 00:50:56:90:78:4d brd ff:ff:ff:ff:ff:ff
    inet 10.2.10.7/16 brd 10.2.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe90:784d/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP
group default qlen 1000
    link/ether 00:50:56:90:0a:54 brd ff:ff:ff:ff:ff:ff
    inet 10.1.200.7/24 brd 10.1.200.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe90:a54/64 scope link
       valid_lft forever preferred_lft forever

VPN-IP’s, like the one allocated by StrongSwan (IPSec), will be also listed in here but won’t be shown with ifconfig!

Playing Westwood’s Red Alert 2 under Linux/Qemu (XP)

At first the bad news: The game can’t be played native under Linux. There are some possibilities to get it run using Wine but that’s some kind of gambling.

There are also many OpenSource-variants like OpenRa or FreeRa (discontinued?) but thats not the same as playing the real game.

20160716_red_alert2_qemu.org_20160716_110429_10182Kmg_thumb.png

So the best way (for me) is playing Red Alert2 using the virtualization-software Qemu with the guest-os Windows-XP.

But hey, why Windows-XP? This operating system shouldn’t be used anymore because of missing updates and therefore many security-holes will appear in the future.

That’s right, but if you’re using Windows-XP only to play some older games it shouldn’t be any problem, even if you disallow access to the internet from the machine. Windows-XP is also the best solution to play those older games. Not only Red Alert 2. Also Stronghold, Sim-City, Freeserf, … can be perfectly played under XP.

Another good reason is the price. You’ll get cheap copies of Windows-XP using eBay or Amazon.

I don’t explain how to install Windows-XP or Red Alert 2 in a virtual environment as this could be found using google. Instead i will show you the perfect command-line which should be used:

kvm -smp 2 -m 4096M -vga cirrus -cpu host -drive file=disk.qcow2,cache=none -boot order=d -net nic,model=rtl8139 -np -cdrom /tmp/ra2.iso -soundhw ac97

Be sure to use the cirrus vga-adapter. Other values like std or vmware won’t work or you’ll get some blank screens when starting Red Alert 2 (But you can hear some sound at least ;-))

Also take care about the iso-file which is used here as /tmp/ra2.iso. The original cd’s can’t be used as they will be not detected by the copyright-protection of Westwood (But it seem’s that qemu can’t forward all low-level calls to the cdrom-driver of linux) So you have to rip the iso’s from the original cd’s. But here’s another problem: The cd’s can’t be easily ripped using dd or similiar commands because of another copyright-protection of the cd itself. You will have to use some special kind of ripping-software like Alcohol or similar.

Another problem is sound-jittering. You can try to decrease the screen resolution of the guest but that won’t work in all cases. A good way will be the use of an external usb-soundcard which will be only used by the virtual guest.

An external usb-soundcard can be included in qemu using the following command-line:

kvm -smp 2 -m 4096M -vga cirrus -cpu host -drive file=disk.qcow2,cache=none -boot order=d -net nic,model=rtl8139 -np -cdrom /tmp/ra2.iso -soundhw ac97 -usb -device usb-host,hostbus=4,hostaddr=4

You can get your values for hostbus and hostaddr using the lsusb-command of linux (So please don’t use the values of my configuration!)

The output of lsusb will be something like:

Bus 004 Device 004: ID 0480:a006 Toshiba America Info. Systems, Inc. 
Bus 004 Device 003: ID 0bc2:5031 Seagate RSS LLC FreeAgent GoFlex USB 3.0
Bus 004 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 004: ID 03f0:134a Hewlett-Packard 
Bus 003 Device 003: ID 046d:c312 Logitech, Inc. DeLuxe 250 Keyboard
Bus 003 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

The first values (Bus and Device) are the values which have to be used as hostbus and hostaddr.

Now it’s time play a game and i hope you’ll enjoy playing some classic games from the last decade(s).

Setting the tab-width in a linux-shell

If you don’t use the same tab-width whithin all your favourite applications then the following might happen from time to time:

mail:/tmp# cat /etc/crontab

0  *  *  *  *     root     /usr/bin/php /root/bin/check_open_ports.php
5    2  *  *  *    root    /root/bin/wittnet_check.sh
18    22  *  *  *    root     /root/bin/check_sites.sh
0     19  *  *  *    root     /root/bin/check_diskspace.sh
0    6  *  *  *    root     /root/bin/daily_db_backup.sh
0      6  *  *  *    root     /root/bin/postgresql_backup.sh
0      7  *  *  *    root     /root/bin/ics/start.sh
0    0  *  *  *    root     /root/bin/learn_spam.sh

This is the output of a crontab which was usually modified by vi(m) and because of the different indentations this looks really bad. In vim i’m using a tab-width of 4 characters, in the shell my tab-width is … unknown!

Unknown until now – I’ve found the tabs command which takes one parameter and this parameter is the size of a tabulator in chars. With tabs it’s easy to set the tab-width in a shell which will be used by programs like cat, tail, …

mail:/tmp# tabs 4
mail:/tmp# cat /etc/crontab

0   *   *  *  *    root     /usr/bin/php /root/bin/check_open_ports.php
5    2  *  *  *    root     /root/bin/wittnet_check.sh
18  22  *  *  *    root     /root/bin/check_sites.sh
0   19  *  *  *    root     /root/bin/check_diskspace.sh
0    6  *  *  *    root     /root/bin/daily_db_backup.sh
0    6  *  *  *    root     /root/bin/postgresql_backup.sh
0    7  *  *  *    root     /root/bin/ics/start.sh
0    0  *  *  *    root     /root/bin/learn_spam.sh

Now everything look’s fine and it’s easier to read this crontab as it was before.

Crontabs and Cronjobs

Introduction

Crontab is one of the famouse services on a linux- and unix-system which hasn’t changed over decades. The configuration-layout is still the same as it was many years and more ago.

Crontab is a system service which starts shell-scripts or programs on a given date and/or time. Each user has his own crontab which can be modified by using the command crontab -e. A typical crontab looks like the following:

*  *  *  *  *   <scriptname>

The first column (first star) represents the minute. The second one the hour followed by day, month and weekday (where 0 means sunday) You can take the example from above if you want to execute your script or command each minute. The placeholder * stands for “every”.

A more realistic example will look like the following. In this case a program named /usr/local/bin/test starts daily at 10 O `clock:

0  10  *  *  *   /usr/local/bin/test

Intervals

In order to define intervals, simply add a slash followed by the interval specified. The following entry starts the program every 5 minutes:

*/5  *  *  *  *   /usr/local/bin/test

Handling output- and error-messages

One must make sure that the script did not output generated because this is the current user by e-mail sent . Runs Amok a job so it can easily be suddenly thousands of messages in the mailbox waiting .

In order to prevent this , the output will be redirected directly in crontab:

0  10  *  *  *   /usr/local/bin/test &> /dev/null

In that case the whole output will be redirected to /dev/null

Using Scripts which are not stored in PATH

A simple user doesn’t have write-permissions to locations like /usr/bin, /bin and so on. Many user will save their scripts to /usr/local/bin but that path isn’t known by the most linux-systems per default.

So you have to extend the PATH-variable with /usr/local/bin. If you only call the script from within cron the best place for modifying PATH will be in the crontab itself. To do this simply add the following PATH-entry to your crontab (Check your current PATH-value and just add /usr/local/bin to it, don’t you use my example if you’re not sure because some path may be missing and this will possibly break your crontab as program’s won’t be found anymore)

PATH=/usr/local/bin:/usr/bin:/bin

0  10  *  *  *   /usr/local/bin/test &> /dev/null

/etc/crontab

This is the system-wide crontab. It is similar to the user crontab with the difference that the user, under which the script/program is executed, has to be specified.

PATH=/usr/local/bin:/usr/bin:/bin

0  10  *  *  *   root  /usr/local/bin/test &> /dev/null

In this case, our script will be started as the root user.

DHT22

Description

The DHT22 is a temperature and humidity sensor. It is the successor of DHT11 only it provides more accurate data but also cost more in the acquisition.

The sensor operates with 3 pins. VCC, GND and Data, but Data isn’t an analog signal. It’s a digital signal which is working like 1Wire but is not compatible to it. You have to write your own library with the protocol of the DHT22 which can be found in the internet.

Specifications

  • Minimal data-polling of 2 seconds
  • Non Dallas 1-Wire compatible
  • More accurate than DHT11
  • 3-5Volt
  • 2,5mA maximum current
  • 4 Pins
  • 2,4g weight
  • 0-100% relative humidity (2-5% accuracy)
  • Temperature range of -40 bis 80° degrees (+/- 0,5° degrees)

Using GDB/GUD within Emacs

As an emacs user i try to fit all my activities within Emacs. This works perfectly well when programming but show some imperfections when debugging programs under Emacs.

The default settings of GUD are not well defined. This applies particularly to projects with numerous source files. GUD will jump between different buffers to show those source-files even if you step through your code. The respective layout is completely destroyed here and it’s hard to follow some focus in here.

The following function will restore a destroyed layout, it’s not a perfect solution but it will work for me.

(defun my-debug-layout ()
  (interactive)
  (if (fboundp 'project-debug-layout)
      (project-debug-layout)
    (gdb-restore-windows)
    (split-window-right)
    (gdb-display-disassembly-buffer)
    (windmove-down)
    (split-window-right)
    (gdb-display-io-buffer)
    (windmove-up)
    (balance-windows)
    (end-of-buffer)
    (message "Default layout")))

So i can reset the layout quickly using the F8 key:

(global-set-key (kbd "<f8>") 'my-debug-layout)

While debugging buffers get still destroyed but using F8 you can easily restore those.

Keep-Alive of SSH connections

Who constantly keeps numerous SSH connections open knows the problem. If you in a compound just not as active as it can happen that the connection breaks off. The reason for this are usually SSH-setting of the client and the SSH server. These detect some “inactivity” (no traffic on the lines going) and end the session.

To prevent this, there is a SSH option named keep-alive specifically located in /etc/ssh/ssh_config and is called:

ServerAliveInterval 5

The interval refers to seconds. In this case, every 5 seconds a keep-alive through the SSH tunnel shipped to signal an activity.

Get Opcode from shell

You’re hacking some binary with your favourite debugger/hex-editor and want to replace some bytes with the opcodes of mov eax, 0x0 but you didn’t know the corresponding bytes of this assembler-statement? So the following simple script will help you out.

You call it like

$ opcode "mov eax,0x0"

and you’ll get the following output:

0000000 b8 00 00 00 00
0000005

opcode is just a simple shell-wrapper which is using nasm to get the corresponding opcode. You can use it as base to add additional extensions like various architectures and so on.

Hex-output is done by the od command (linux-standard)

Here’s the source of opcode:

#!/bin/bash
#
# Usage: opcode "mov eax,0x0"
#
# Output:
# 0000000 b8 00 00 00 00
# 0000005
#

my_opcode() {
        ID=$$
        echo -e "BITS 64\n $*" > /tmp/$ID.tmp.S && nasm -f bin /tmp/$ID.tmp.S -o /tmp/$ID.tmp.o && od -t x1 /tmp/$ID.tmp.o
        rm -f /tmp/$ID.tmp.o /tmp/$ID.tmp.S
}

my_opcode $@

Use cut&paste to copy the text from above and save it to a file called opcode (or opcode.sh if you prefer some extension)

Freeserf, open-source clone of “Die Siedler”

Another pearl of a great open-source game is called freeserf. The original-version is called “Die Siedler” or Serfcity.

freeserf1

You’ll need the original data-packages of the original-game from BlueByte to play this game but it’s worth to do so.

Have a look at http://jonls.dk/freeserf/ but be aware that you’ll need some developer-skills to run this game because only the source is available (and, of course, you’ll have to get the data-files first) Maybe someone will create some binaries to make it more easier to play this game.