Netcat Tar Pipe

Sometimes SCP, SFTP or other methods of file transfer aren’t available. Using netcat and tar, files can be archived and sent over the network on the fly, like this: On the destination server: mkdir /destination/directory cd /destination/directory nc -l 7000 | tar x On the source server: cd /source/directory tar cf - * | nc destination-hostname 7000

March 1, 2011 · Ed Randall

Configure logging in IPtables

Its useful to have a dedicated logfile which contains details of packets which are dropped or rejected by your iptables firewall. This will allow to you see when connection attempts are being made to your server by IP addresses which are being blocked. This can also be extremely useful when troubleshooting your iptables firewall. If you’re not up to speed with iptables, then you’ll need to find another guide to work through....

November 25, 2010 · Ed Randall

Setting up mysql replication

On the primary DB node: Enable binary logging in my.cnf: [mysqld] log_bin=mysql-bin server-id=1 Restart MySQL /etc/init.d/mysqld restart Create a user for replication: mysql> GRANT REPLICATION SLAVE ON *.* TO 'user'@'1.2.3.4' IDENTIFIED BY 'slavepass'; Find filename of binlog: mysql> show master status; Do the mysqldump of the database you want to replicate: mysqldump -c –create-options -u root -ppassword –lock-tables databasename > dump.sql Copy the sql file over to the slave: scp dump....

November 24, 2010 · Ed Randall

Mounting disks by label in Linux

USB hard disks are often allocated different device names by Linux each time the system boots. For example: what is currently recognized as /dev/sda1 may well end up being /dev/sdb1 after a reboot. To get round this, it is possible to mount disks by label rather than device name by taking the following steps (as root): First of all, you need to see if the partition in question already has a label:...

November 24, 2010 · Ed Randall

Creating a self-signed certifcate for apache

Creating a self-signed certificate for an apache server is fairly straightforward. The following steps show you how to do it on an ubuntu / debian based system running apache: If it doesn’t already exist, make the directory for the key, csr and certificate to go in: mkdir /etc/apache2/ssl Go to that directory: cd /etc/apache2/ssl Generate the private key (Enter a passphrase when prompted, we’ll remove this later) openssl genrsa -des3 -out server....

November 24, 2010 · Ed Randall

Change case of all files in a directory

Here’s an easy way change the names of all files in a directory from upper to lower case (note that we are using ls -1 and not ls -l in this example): user@server:~/test$ ls -1 FIVE FOUR ONE THREE TWO user@server:~/test$ for file in `ls -1` ; do newfile=`echo $file | tr .A-Z. .a-z.` ; mv $file $newfile ; done user@server:~/test$ ls -1 five four one three two To invert the process, simply change reverse the options passed to the ‘tr’ command like this:...

November 24, 2010 · Ed Randall