Wednesday, September 16, 2015

ipython && tmux - saving history to a file

Hey,

I had an ipython console open inside a tmux split window and I needed to save the history to a file.
Since I can't copy & paste the data from the screen (I was in the middle of a session, so the next time I would configure it correctly using this).

So I found a quicker way, Roberto Z wrote in his comment that in order to save the session's history you can use readline package:

import readline
readline.write_history_file('/home/user/current_history')

This works like a charm in Ubuntu.

- Tal Kain

Wednesday, September 9, 2015

Linux: iptables: Removing a collection of iptables rules at once

Here is a small trick for removing several iptables rules at once,

Let's assume we would like to add some rules:
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
I can use the comment match and add a comment to this line:
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE -m comment --comment "SOME_COMMENT"

Now, cleaning all the relevant rules in a simple command would be:

# iptables-save | grep -v SOME_COMMENT | iptables-restore

 Probably not the best way to do it, but it's simple and fast.


Have fun,
-Tal Kain

Wednesday, September 2, 2015

Installing NVIDIA CUDA on an Amazon Web Services (AWS) machine (Ubuntu 14.04)

Disclaimer: I wrote this post several months ago and did not publish it for unknown reason, I assume that the information below is still relevant and correct.

While trying to install the machine, I started my research by reading Traun Leyden's great blog post: http://tleyden.github.io/blog/2014/10/25/cuda-6-dot-5-on-aws-gpu-instance-running-ubuntu-14-dot-04/ (you should too)

Amazon offers two types of machines that includes GPUs (https://aws.amazon.com/ec2/instance-types/#g2)
High-performance NVIDIA GPUs, each with 1,536 CUDA cores and 4GB of video memory
While writing this post, I used the g2.2xlarge machine, but you can also use the 8xlarge.

This will be quick and simple:

1. Make sure you are fully up-to-date
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
 When prompted, choose the "install maintainer package...."

2. Reboot the machine (so it will load the new kernel)
3. Install the kernel's header files
sudo apt-get install -y linux-image-extra-virtual linux-headers-`uname -r`
3. Configure the xorg-edgers PPA

sudo add-apt-repository ppa:xorg-edgers/ppa
sudo apt-get update
4. Install the NVIDIA's CUDA repository package
OUTPUT_PATH=/tmp/cuda.deb
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.0-28_amd64.deb -O ${OUTPUT_PATH}
dpkg -i ${OUTPUT_PATH}

 5. Update the package manager and install CUDA
sudo apt-get update
sudo apt-get install cuda
6. Make sure everything is installed as expected:
sudo nvidia-smi -a

7. You can also compile and run a sample to make sure everything is ready:
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
make
./deviceQuery

That's all!


- Tal Kain