Monday, September 9, 2013

Simple copy of file between linux boxes with netcat

I am still pretty new all this Linux sysadmin stuff, so when I get new tricks to to help me I clap my hands and quickly write it down. So here goes.

If you need to copy large amounts between instances, you might not have access to copy between the specified instances via scp. Here netcat, nc, can help you. It opens a direct connection between the two instances, so you can stream bit from one to the other.

Example

I want to send file1.txt from instance A to instance B.

On instance B do:

$ tar -cf - . | nc A_ip 4000

On instance A do:

$ nc -l 4000 | tar xvf file1.txt

If you need to send over a lot of files you can use the following on instance A:

$ nc -l 4000 | tar xvf -

If you are sending a a huge amount of data, you might need to throw gzip and gunzip in to the mix:

$ tar -cf - . | gunzip | nc A_ip 4000
$ nc -l 4000 | gzip |tar xvf file1.txt

Of course you need to make sure the ports are open for communication, but most instances have at least one open port that can be used. Just make sure the port is not use by other programs.

Note that netcat syntax differs a bit between the original unix version and the OpenBSD version. The above examples are in the OpenBSD variant.

Reference

 - http://www.commandlinefu.com/commands/view/2536/using-netcat-to-copy-files-between-servers


Friday, March 15, 2013

Sad day for people who can concentrate for more than 2 minutes

Its a sad day today. Google Reader have been terminated!

In the newest spring cleaning from Google, Google is shutting down Google Reader along side a lot of other stuff. I am not to say wether this is good business or not  as seen from Googles point of view. But from my point of view, its a sad day.

I have been using Google Reader for more than 6 years and have grown accustomed to its simplicity, easy navigation and general ease of use. These characteristics are, in my opinion  not to be found any where else in any RSS reader, hence a sad day.

The main thesis out in webland is that most people now a days use social media for keeping track of news and therefor there is no use for Google Reader/RSS anymore. That might be right for day to day news, "Elephant ate my baby" kind of stuff, but to me and a lot of others, there a re simply to much stuff I need to keep my eye on and social media is simply going by to fast and to shallow. I need a place where everything is aggregated and stays there until I have decided that it should not any more. Social media today simply does not do this very efficient today. Most social media today is like a flashing bilbard on Time Square, things flashing by to feed people in a hurry and people who cannot concentrate for more that 2 minuts at the time. My guess is that most people disagree with me on that point, but from where I am sitting this is the truth.

Enough ranting on social media for now. The bottom line is that I will be missing my faithful companion Google Reader. Hopefully I will find a new friend that will support me in my daily work and help me stay up to date.

Wednesday, June 6, 2012

Installing PCNTL for PHP on OSX Lion

Today I needed to install the PCNTL extension for PHP for a tutorial session at the Dutch PHP Conference. And since I am working on OSX Lion, this of course gave some problems due to the rather odd installation of Apache and PHP on OSX.

Several sites on the web gave quick guides for this, but still, as always there are a few things you need to keep in mind for it all to work. I will try to walk through the process as detailed as possible:

First start by installing Xcode. You can get the latest version from the App Store. NOTE that the App Store only have the latest version of Xcode, so if you need a version for Snow Leopard or older, you need to dig deep on the web (https://connect.apple.com is a good place to start).

Next you need to install the Command Line Tools from Xcode. You do this by opening Xcode, go to Preferences (CMD + ,) -> Downloads -> Components and hit install on the Command Line Tools. You can get the Command Line Tools without installing Xcode via https://connect.apple.com

Now you need to find out what version of PHP is installed on OSX

$ php -v
PHP 5.3.10 with Suhosin-Patch (cli) (built: Feb 20 2012 22:55:53) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

and then get the source code for that version

$ curl -O http://us.php.net/distributions/php-5.3.10.tar.gz

When the download have finished, you should unpack, find the PCNTL extension, phpize, configure, make and then make install

$ tar -xzvf php-5.3.10.tar.gf
$ cd php-5.3.10/ext/pcntl
$ phpize
$ ./configure
$ make
$ sudo make install

If phpize is complaining, you are probably missing autoconf. The easiest way to install autoconf is via Homebrew. You install Homebrew by doing

$ /usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

The first thing you need to do afterwards is to run

$ brew doctor

to find out if any dependencies are missing. Homebrew will telle you what to do, if any is missing.

Lastly you need to enable the PCNTL extension. Do this by adding the following to your php.ini

extension=pcntl.so

if you do not know where your php.ini file are, you probably need to create on, by doing

sudo cp /private/etc/php.ini.default /private/etc/php.ini

Restart Apache and verify that the PCNTL extension are loaded correctly

$ sudo apachectl restart 
$ php -m | grep pcntl 
pcntl

If the PCNTL extension for some reason is not loaded, try and copy the pcntl.so from the compiled source code to the extensions directory

$ sudo cp php-5.3.10/ext/pcntl/modules/pcntl.so /usr/lib/php/extensions/no-debug-non-zts-10090626/

Restart apache and verify the the PCNTL extension is loaded.

Resources:

Tuesday, January 17, 2012

An odd error with VirtualBox on OSX 10.6

I recently updated my version of VirtualBox on my OSX 10.6 box to version 4.1.8 and it suddenly stopped working. When I tried to start on of the virtual I was given the following error message:

Failed to load VMMR0.r0 (VERR_SUPLIB_WORLD_WRITABLE).


After searching the Internet a bit I found a highly unusually solution. Remove write permission for Other!!

$ chmod o-w Applications

Why this work, I do not know but it does. If you know why, please leave a comment.

Wednesday, December 14, 2011

Installing Gearman on Ubuntu 10.04

This is a quick guide on how to install Gearman on Ubuntu 10.04 LTS.

I found numerous guides online, but none of them seems to do the complete trick for me. I know most installations are different from each other, so that is probably the reason why non of them worked on my setup. So here is my addition to the list of Gearman install guides.

  1. The first thing you need to do is to find a PPA repository with an updated version of Gearman. The one bundled in Ubuntu by default is very old. The only reasonable up to date repository I could find is

    https://launchpad.net/~gearman-developers/+archive/ppa

  2. If you do not have the add-apt-repository command installed, you have to install it

    $ sudo apt-get install python-software-properties

  3. Now you can add the repository by issuing the following command

    $ sudo add-apt-repository ppa:gearman-developers/ppa

  4. After adding the repository, you should update the package list

    $ sudo apt-get update

  5. Now you can install the latest version of Gearman

    $ sudo apt-get install gearman gearman-job-server gearman-tools libgearman4 libgearman-dev

    Please note that as of December 2011 the latest update to the repository was in May 2011 with Gearman version 0.14.
  6. You are now free to install Gearman extension to whatever language  you like. Most requirements should be covered by the above mentioned packages.
    You can start the Gearman job server by the following comand

    $ gearman -d
References