A chronological documentation test project, nothing serious, really!

13 Nov 2012 Script to delete files listed in a file

This is a short one liner bash script to delete files in a file.
The script also handles filenames with space in them.

$ while read file; do rm "$file"; done < filename.txt

To generate a filename.txt file by searching for a specific pattern you can use the following command

$ find / -type f -name "filname*" > filename.txt

You should verify the files you are about to delete before you invoke this script!

Tags: ,

Posted by

24 Sep 2012 Using rsnapshot as backup solution

This post describes short how to use rsnapshot as a remote filesystem snapshot utility, based on rsync that I use as my personal backup tool.
I have started using rsnapshot after using rsync and rdiff-backup and lost files because of file corruption.
rsnapshot is a great backup utility because it hardlinks files if they already exists and your backups does not take much more space than the actual filesystem you are backing up.
You need to configure passwordless SSH connection from the backup server to the file server if you plan to run this as a automated job using crontab.

This is the content of my config file (/root/scripts/rsnapshot-home.conf) to backup my remote fileserver

config_version  1.2
snapshot_root   /media/Backup/
cmd_cp  /bin/cp
cmd_rm  /bin/rm
cmd_rsync       /usr/bin/rsync
cmd_ssh /usr/bin/ssh
cmd_logger      /usr/bin/logger
cmd_du  /usr/bin/du
interval        daily   7
interval        weekly  4
interval        monthly 3
verbose 2
loglevel        4
logfile /var/log/rsnapshot-home.log
exclude_file    /root/scripts/rsnapshot-home.exclude
rsync_long_args --delete        --numeric-ids   --delete-excluded
lockfile        /var/run/
backup      files/

The config file is tab delimited so you will get errors if you use space instead!

Running manual daily backup can be done with the command

# rsnapshot -c /root/scripts/rsnapshot-home.conf daily

You do now have a folder structure like this with your backups


Where daily.0 is the newest backup.

The backup files are store in the same form as in your file server so you can browse them using a regular file browser.
You can read more about restoring backups on the rsnapshot HOWTO.

You can also configure a report to be sent after every backup with the perl script but I will not be covering that in this post.

Tags: ,

Posted by

26 Jan 2012 Disable DLNA in Windows 7

If you are using your Windows 7 and have a active wireless network, then the chances are that you are sharing your media files with DLNA enabled devices like smartphones, TVs with wireless access and media centers.
This HOWTO describes how you can disable DLNA in Windows 7.

  1. Type “Manage advanced sharing settings” in the Start Menu
  2. Go to “Home and Work”
  3. Under “Media Streaming” you click the “Choose media streaming options” link
  4. Click the “Block all” button followed by the “OK” button

You have now disabled DLNA sharing on your computer.

Tags: , ,

Posted by

13 Jan 2012 Using Lsyncd to perform “live” syncronization of a local directory to a remote directory

This post is a short HOWTO and describes how you can install and run lsyncd to perform a rsync syncronization from local to a remote server using SSH.
Lsyncd is a daemon to continuously synchronize directory trees and relies on inotify. If you need real live syncronization DRBD might be a better alternative since it is a block level syncronization.

Installing Lsyncd 2.0 from source on CentOS 6
Lsyncd is not included as a package in CentOS 6, so you need to download the source file from
You should have rsync, GCC and lua-devel installed on your system before you continue installing Lsyncd.

# yum install rsync lua-devel

Unpack the lsyncd source file and run the following commands from the unpacked file

# configure 
# make
# make install

make install copies the compiled files and install them to the right directories in your system.

I need to configure a non password SSH communication between the two servers with a shared SSH key.
On the source server run the following command to generate a SSH key, if you have not done this already.
Remember to do this as the user you are going to perform the sync with.

# ssh-keygen

Secure copy the generated SSH key from the source server to your target server

# scp ~/.ssh/ root@remoteserver:/tmp

On the target server you need to add the copied SSH key to your existing authorized keys file.
Also remember to do this with the user you are going to connect with from the source server.

# cat /tmp/ >> ~/.ssh/authorized_keys

If you do not have this file, just create it using the touch command described below

# touch ~/.ssh/authorized_keys

Test if you can ssh without a password from your source server to the target server.

I have made a config file, /root/scripts/lsyncd.conf that tells Lsyncd where to put the log- and statusfile. That it should be running as a daemon in the background, and a sync should occur after 900 seconds (15 minutes) if there have not been any filesystem changes and there should not be more than 6 parallell Lsyncd processes.

settings = {
   logfile      = "/tmp/lsyncd.log",
   statusFile   = "/tmp/lsyncd.status",
   nodaemon     = false,
   maxDelays    = 900,
   maxProcesses = 6,

sync{default.rsyncssh, source="/path/on/source/", host="", targetdir="/path/on/target/"}

To start lsyncd you run the command

# lsyncd /root/scripts/lsyncd.conf

You should now see a Lsyncd process running as a daemon on your system. It performs a sync when you start and then waits for any filesystem changes or sync after 900 seconds.

If you would like Lsyncd to start at boot, just add the following line to the bottom of file /etc/rc.local

lsyncd /root/scripts/lsyncd.conf

You do now have a working secure rsync syncronization between two servers.

What directories you are syncing

# tail -f /tmp/lsyncd.status

What is happening now

# tail -f /tmp/lsyncd.log

Tags: , , , , ,

Posted by

02 Jan 2012 How to join *.001,*.002,… files from your Linux terminal

This is a easy way to combine/join/merge several .001 .002 .003 etc files to one file.

# cat filename.avi.* > filename.avi

The .001 .002 .003 files can be deleted after you have verfied that the files have merged together successfully to one file.

If you were using Windows you would normally use a software like HJSplit or similar.

Tags: ,

Posted by