Archive

Posts Tagged ‘linux’

Simulating Slow Connections in OS X or Linux

April 10th, 2013 Comments off

Simulating Slow and Laggy Connections

 

Do you want to simulate how it feels to load your site from a mobile connection (If it’s AT&T just turn off your network for an accurate simulation- I kid, don’t sue. But seriously AT&T, figure it out.) or from a laggy network? In OS X or Linux, you’ve got everything you need already installed: ipfw (IP firewall and traffic shaper control).

Create a Pipe

Configure a pipe with the appropriate bandwidth (I’ve also added a 200 ms response delay in this example).

sudo ipfw pipe 1 config bw 16bit/s delay 200ms

Attach the Pipe

In this example we’re going to use port 80, but you can also use port 443 or any other port that you may be testing communication on. Additionally, you can attach the pipe to multiple ports.

sudo ipfw add 1 pipe 1 src-port 80
sudo ipfw add 2 pipe 1 dst-port 80

That’s it!

Wait a second, you say! Now your network connection is completely throttled and everything is running terribly! You need to delete both ipfw entries and the pipe that were previously created.

Here’s how you undo what you’ve just done:

sudo ipfw delete 1
sudo ipfw delete 2
sudo ipfw pipe 1 delete
Categories: Linux, Tutorial Tags: , , , ,

Encrypting a tar or gz (gzip) File with OpenSSL

July 17th, 2012 3 comments

When you have sensitive data that you need to transmit but want to make it easy to encrypt and decrypt it, use some standard tools to get the job done!

I recently had an issue where a client was using OS X laptops running an Admin panel written in PHP on MAMP in an environment that may or may not have an internet connection. The problem was that they needed to be able to dump their database data into an encrypted file so that they could send the data off when they get a connection (via email, upload, who knows). My initial response was to use gpg to encrypt the file and hand out the keys to the people who would eventually be reading the data.

Turns out, this was going to be a nightmare and I needed something ‘easier’. How about encrypting a tar file with OpenSSL? Bingo! This solution uses utilities that are already on the machine and no installations need to be performed. The reason this was such a big deal is because the laptops running this software will be all over the world with various levels of technical acumen and it will be a nightmare to make sure every single laptop has been updated correctly.

Encrypting Your File

tar and gzip the file, then encrypt it using des3 and a secret key.

tar cvzf - mysql_dump.sql | openssl des3 -salt -k #YOUR PASSWORD# | dd of=encrypted_mysql_dump

That simple!

Decrypting Your File

dd if=encrypted_mysql_dump |openssl des3 -d -k #YOUR PASSWORD# |tar xvzf -

Essentially, just call all the commands in the reverse order.

Download the Utility Scripts

Download them!

Measuring Download Speed from Linux Command Line

April 16th, 2012 Comments off

I recently needed to test the network speed of the ISP from my Ubuntu 10.04 LTS server. I was trying to think of a better way to test it than going out to a Linux Distro's web site and downloading an ISO from them. I stumbled across this post on StackOverflow that had a URL to a speedtest.net test file and my speedtest scripts were born. I created two scripts, one utilizing wget and on utilizing curl. A lot of machines don't come with curl by default, but it has a lot more output than wget does while downloading.

 

What Do They Do?

The scripts utilize wget or curl to download the speedtest.net 500M test file and you can view the speed results in real time. This is an entirely unscientific method of testing your speed, but much better than say, going to Ubuntu and downloading their latest ISO via wget. Finally, the output is set to go to /dev/null, which means it simply throws away everything it downloads (no cleanup).

 

The Code

Download both scripts here

speedtest-wget.sh

#!/bin/bash
wget --output-document=/dev/null http://speedtest.wdc01.softlayer.com/downloads/test500.zip

speedtest-curl.sh

#!/bin/bash
curl -o /dev/null http://speedtest.wdc01.softlayer.com/downloads/test500.zip	
Categories: Linux Tags: , , , ,

Quickly Clean Up .svn Directories Recursively

January 6th, 2012 Comments off

Did you forget to export your subversion project before copying it? Inheriting a subversion mess? Here’s how you clean it up real quick on Mac and Linux:
Change to the root of your target project/directory

find ./ -name ".svn" | xargs rm -Rf
Categories: Linux Tags: , ,

Install / Upgrade PHP 5.3 on CentOS 5 / RHEL 5

September 6th, 2011 Comments off

As I was setting up a staging VM (CentOS 5), I quickly realized I could only get PHP 5.1 from the standard repositories. Thanks to this blog post, I was able to quickly get up and running with PHP 5.3.

From the command line on your server, run the following:

wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh epel-release-5-4.noarch.rpm
rpm -Uvh remi-release-5.rpm
yum --enablerepo=remi update php php-* mysql

This, of course, assumes that your LAMP stack is already installed. If not, you would want to replace ‘update’ with ‘install’.

Make sure that you run the last update command (if you’re running an update) as noted above. Not including one of the three packages will result in a bunch of file conflict errors.

Categories: Linux Tags: , , , , ,