Posts Tagged ‘linux’

Bash script to fix indentation for C++ code

28 November 2012 Leave a comment

This small scripts allows me fix the indentation of C++ source files with very little effort.


  1. Drop one or more C++ source files in the “toindent” folder
  2. Run the script “./ toindent” (this calls the bcpp indenter to indent all files in the ‘toindent’ folder)
  3. Done

There are some options for step 2:

  • Select one file to indent: “ file.cpp”
  • Select all files in the ‘toindent’ folder: “./ toindent/”
  • Select only files with a certain extension in a folder (e.g. “.h”):  “./ toindent h”


Indentations options can be changed in the “bcpp_indenter.cfg” file.


Automated multiple choice exam grading

6 June 2011 4 comments

I wrote a little tool for automated multiple choice exam grading.

The idea:

  1. Students receive two sheets: one questions sheet and one answer sheet
  2. They indicate their correct answer by erasing the wrong answers (letters) on the answer sheet (see scan on the right)
  3. When all students have finished their exam, the answer sheets are batch-scanned and send to some email address.
  4. The server receives this email, starts processing the scans, calculates the grades and sends out a report to the lecturer

Read more…

Backup script: encrypted, offsite, incremental backup (rsync, rdiff-backup, encfs)

17 January 2011 2 comments

In this post I will explain a small (~100 lines) backup script I use to make offsite automated backups of several computers.

Overview of the scripts’ actions

  1. Mount a local folder using encfs (the backup files are written in this folder)
  2. Do an incremental backup with the local encfs folder from step one as the destination. Using rdiff-backup with a remote location as the target sometimes resulted in failed/broken backups on systems that frequently go offline. (laptops)
  3. Send the encrypted files to an off-site server (any server with ssh access will do, I use the quite cheap servers.
  4. Send all logged events and an overview of the incremental backups over email

Read more…


6 January 2011 1 comment

I have recently been testing BackupPC, a high-performance, enterprise-grade system for backing up Linux, Windows and MacOSX PCs and laptops to a server’s disk.

Initial configuration is a little bit daunting, you should (must) read the documentation and the self explanatory config files…

Interesting features:

  • autonomous system: no client-side software or user interaction is needed
  • the intelligent pooling system mimizes disk usage by detecting duplicate files (+bzip2 compression)
  • very flexible configuation files

I added one small “feature” based on the following blog post by Ted Carnahan: only run backup when laptop is running on AC-power. (the following works on a Lenovo Z61m Thinkpad and can be adapted to work on any other linux system)

Add this to the config file:
<code>$Conf{RsyncClientCmd} = '$sshPath -q -x -l backuppc $hostIP grep -q on /proc/acpi/ac_adapter/AC/state && $rsyncPath $argList+';</code>

When the laptop is on AC-power, the return value for the code in bold is 0, and the backup continues. When on battery power, a non-zero return value results in an aborted backup.

Categories: linux, system administration Tags: , ,

Arch Linux & Pacman

1 November 2009 Leave a comment

A week ago I switched from Debian 5.0 to Arch Linux. The initial learning curve was not that challenging as everything is perfectly documented in the ArchWiki.

The result is a snappy new system with very up to date packages, especially compared to Debian Stable.

One thing that kept bugging we was the syntax for the “Pacman” package manager. To resolve this small issue I added some aliases to $HOME/.bashrc

alias pacup="pacman -Syu" %(system update)
alias pacin="pacman -S" %(install packages)
alias pacinfo="pacman -Si" %(show package info)
alias pacrem="pacman -Rn" %(remove package)
alias pacmirror="reflector -l 8 -r -o /etc/pacman.d/mirrorlist" %(update repository list & rank fastest mirrors)
alias pacsearch="pacman -Sl | cut -d' ' -f2 | grep " % (search package database)

Increase Dropbox size using transparent compression (FuseCompress)

9 September 2009 Leave a comment

It is possible to increase the storage size of a Dropbox account by using transparent file compression using FuseCompress.

FuseCompress provides a mountable Linux file system which transparently compresses its content.
Files stored in this file system are compressed on the fly and Fuse allows to create a transparent interface between compressed files and user applications.

By storing the compressed filesystem in your Dropbox you can increase it’s size by +/- 20-60% (depending on your files, filetypes, compression algorithm,… )
Fusecompress supports several compression algorithms: zlib, lzo, bzip2, xor.

Bzip2 has the highest compression ratio and the lowest speed, but files in Dropbox are never really big, and I never add many files at one time to my Dropbox folder anyway. That is why I chose to use bzip2.

Little “walkthrough:” (tested on Debian stable, should also work on Ubuntu Karmic)

FuseCompress is not available on debian stable, but it can be installed from the testing repository. (guide:
FuseCompress is not available on Ubuntu Jaunty 9.04, but I suppose it can be installed from the Karmic repository.

Fusecompress depends on fuse, if it was not installed before, you might have to logout before you can use FuseCompress.

From here on you must be using your own account (not root), otherwise you might run into some file permission and ownership problems.

Create two folders: one for the compressed archive (in you Dropbox folder), one for the mountpoint (the place where you will store your files.
mkdir $HOME/Dropbox/compressedfolder
mkdir $HOME/CompressedDropbox

Create and mount the compressed filesystem:
fusecompress -o fc_c:bzip2 $HOME/Dropbox/compressedfolder $HOME/CompressedDropbox

Enjoy your new compressed Dropbox!

Some tests to make sure everything is working ok:

Show total folder size: (run command inside the mountpoint)
du -sh
Show total filesize in your compressed-dropbox before compression.
du -sh --apparent-size

Backup using rdiff-backup: a bash select menu

23 February 2009 Leave a comment

This is a bash backup script, that uses rdiff-backup to perform “semi-automatic” backups. (I need to press two keys, to start a backup)

So, what does it do?

First there are some global options (mainly for debugging)
The exclude and include variables are links to the include/exclude files. (in this file you specify which folders to backup)
The “backup” variable: this is where rdiff-backup gets started.

Then a select menu is drawn (as described in a previous post.
The first option checks if my external HDD is mounted, if it is, it does the backup.
The second options checks if I am at home (based on IP), if I am it does the backup to a local file server.
The third option does the same, but on my work network. (it uses public IPs, so it is removed)
The fourth option (“l”), lists the different versions on my local backup.
The “p” option pulls some other backups that are automatically generated on a server to my laptop.

options="-v 5 --print-statistics "
exclude="--exclude-globbing-filelist $HOME/.scripts/tools/backup-lists/exclude"
include="--include-globbing-filelist $HOME/.scripts/tools/backup-lists/include"
backup="rdiff-backup $options $exclude/$target $include/$target --exclude '**' / $backuppath"
while :
echo "****************************************"
echo "* Backup using rdiff-backup *"
echo "****************************************"
echo "* [1] Backup to external hdd *"
echo "* [2] Backup to server @home *"
echo "* [3] Backup to work-server *"
echo "* [l] List increments ext hdd *"
echo "* [p] Pull backups work-server *"
echo "* [0] Exit/Stop *"
echo "****************************************"
echo -n "Enter your menu choice [1-5]: "
read yourch
case $yourch in
1) target="ext-hdd"
mount | grep /media/disk-1 > /dev/null
if [ $? -eq 0 ]
echo loop1
echo "Backup to external hdd finished, Press Enter to continue. . ."
echo "Error no external harddisk connected!"
echo "Press Enter to continue. . ."
exit 0;;
2) backuppath="server.local::/zfs-raidz/backup/autobackuplaptop/"
ifconfig | grep 192.168.123 > /dev/null
if [ $? -eq 0 ]
echo "Backup to ubuntuserver finished, Press Enter to continue. . ."
echo "You are not at home, ubuntuserver not reachable"
echo "Backup to ubuntuserver failed, Press Enter to continue. . ."
exit 0;;
3) backuppath="work...."
l) rdiff-backup -l --list-increment-sizes /media/disk-1/autobackuplaptop
echo "Press Enter to continue. . ."
exit 0;;
p) scp -rp -P 55555 me@ $HOME/data/backup
echo "Press Enter to continue. . ."
exit 0;;
0) exit 0;;
*) echo "Oopps!!! Please select 1,2,3,4, or 5";
echo "Press Enter to continue. . ." ; read ;;