Using netcat and tar to quickly transfer files between machines

So you have lots of data to transfer between two machines over ethernet. A nice quick and dirty method is to use netcat and tar. This is by no means secure, but if you haven’t got the time or desire to setup NFS, FTP, Samba, or wait hours for scp to do its job then this can save you a lot of time.

Linux System using tar and netcat

On the receiving end do:
# netcat -l -p 7000 | tar x

And on the sending end do:
# tar cf - * | netcat otherhost 7000


Depending on your hardware you might want to use compression with tar. You’ll probably find your hard disk drive is a bottleneck on a fast network. Compression is useless if you can’t saturate your network and will probably just slow things down. tar cf – * is copy everything in the current working directory. And your files will be untared at the other end from where you started the listening netcat. It won’t be obivous that the operation is finished so you’ll need to check network activity or top. This is indeed quick and dirty.

OpenBSD using tar and nc

OpenBSD usually offers a much tighter system rather than the mess you have with Linux. OpenBSD has its own verison of netcat just refered as nc. The tar command is less sloppy than what you find in Linux. So if you’re using two OpenBSD machines then one would do the following.

On the receiving end do:
# nc -l 7000 | tar -xpf -

And on the sending end do:
# tar -cf - * | nc otherhost 7000

It appears that the OpenBSD rewrite of netcat is now in Debian Sid. The package is netcat-openbsd.

Moving LVM images between machines without ssh

On the receiving end do:
# nc -l 7000 | dd of=/dev/mapper/vgfoo-lvbar bs=32768

And on the sending end do:
# dd if=/dev/mapper/vgbaz-lvquz bs=32768 | nc otherhost 7000


Extracting and repacking an initrd image

If you want to change the contents of an initrd image you need to extract it, make the changes and repack it. This is how you do it.

Open a bash terminal as root. Create a working directory, i will use `initrd`. Then create a directory called `root` in your working directory. Copy the initrd image to your working directory. To extract:

cd root
gzip -cd ../initrd.gz | cpio -i

Make the changes in the root directory

Repack the initrd image.

find | cpio --quiet -o -H newc --owner=0:0 | gzip -c9 -n > ../new_initrd.gz

Script to set file permissions on a shared document tree

When using a shared document tree you probably want to keep the the same groupid when saving and creating documents. To do this you set a sticky bit on the folder. I wrote a script to set/correct the permissions in a shared older.

#! /bin/sh
# shellscript to set user permissions on files and folders
# it also sets a sticky bit for the group on all subfolders
# primarily for use on shared folders

if [ "$1" != "" ] && [ "$2" != "" ]; then
        echo "Setting file group..."
        find "$1" -type f -print0 |xargs -0 chown :"$2"
	echo "Setting file permissions..."
	find "$1" -type f -print0 |xargs -0 chmod 660
	echo "Setting folder group..."
	find "$1" -type d -print0 |xargs -0 chown :"$2"
	echo "Setting folder permissions..."
	find "$1" -type d -print0 |xargs -0 chmod 2770
	echo "USAGE:"
	echo "    xperm PATH GROUP"

Setting up DHCP and DNS services on your own network

In most home networks the role of DHCP and DNS server is performed by the router supplied by your ISP. This is fine until you want more complex things as PXE boot or an internal DNS view. To use these functions you need to run a server in your network. This can be an old PC or – if you are environmentally conscious – a device with a low energy consumption. I prefer an old – atom based – thin client. Continue reading

Converting video to mp4 (H.264) and WEBM with avconv (ffmpeg)

Avconv is a fork of ffmpeg used by debian and ubuntu. For now they use the same commandline syntax. Avconv can convert almost every video format there is. I am using it to convert my video’s to mp4 and webm format. These formats are compatible with most HTML5 browsers. I use the video.js┬álibrary to select which format to use and to provide a flash fallback (mostly IE).
Continue reading