SCP over a proxy/tunnel to a target machine, from your local machine

bash, ssh

For a work project, I was required to take copies of files from one machine at one data center, and copy those files [via scp] through a tunnel and a bastion server at another data center, and then onto a variety of different machines there.

This proved to be a little trickier than I thought, but ~/.ssh/config can be easily setup to ensure that you can access remote machines via proxies very quickly and easily.

If you do not have a ~/.ssh/config file, it is OK to create it. Just ensure that, if you receive “bad owner or permissions” for your ~/.ssh/config file, you adjust them to fix:

chmod 600 ~/.ssh/config

After that, you need to then start adjusting the config file. From my local machine, I setup the following rules:

Host target_host
 User my_username
 HostName target_host
 ProxyCommand ssh my_username@proxy_machine nc %h %p 2> /dev/null

Using these rules, I was able to ssh into the machine by using just ssh target_host from my local.

On the proxy machine and target hosts, you can also easily add some ssh keys so that you can copy files without the need for a password.

Apache failure : Warning: DocumentRoot does not exist

apache

If you notice that when you restart or start httpd/apache and you notice a DocumentRoot does not exist error, but the DocumentRoot does in fact exist; the chances are you need to adjust your settings for /etc/sysconfig/selinux. Simply alter the setting to ‘disabled’ for selinux, reboot the machine, and then attempt to start apache.

Take a mysqldump, tar gz it – all in a handy one liner

bash

I wanted to take a mysqldump of one database, then compress it into a .tar.gz file and all as quickly as possible and with one command.

It’s considerably quicker to import a mysql database from a .gz file, and so this line was very useful for me:

mysqldump my_db -u root | gzip -c | cat > my_db-$(date +%Y-%m-%.%M.%S).sql.gz

Killing a mass of queries from MySQL

mysql

to kill a whole bunch of mysql queries in one go, I used something like this that you can adapt for your own use:

select concat('KILL ',id,';') from information_schema.processlist where Host like 'some-sexy-server-ws%';
select concat('KILL ',id,';') from information_schema.processlist where Host like 'some-sexy-server-ws%' into outfile '/tmp/a.txt';
source /tmp/a.txt

sorting mysql processlist by order of date

mysql

How to set a mysql processlist to display by Time of query to help locate long running queries:

mysql> \P awk -F\| '$2 ~ /[0-9]+/ && $6 ~ /Sleep/' | sort -t \| -k 7 -n -r
PAGER set to 'awk -F\| '$2 ~ /[0-9]+/ && $6 ~ /Sleep/' | sort -t \| -k 7 -n -r'
mysql> show processlist;

CUPS / Samba / Wireless Printing randomly stops working on Ubuntu

CUPS, linux, samba

I’ve setup a CUPS (Common Unix Printing System) wireless printer sharing in our office, and occasionally the wireless printing randomly stops working. In addition, Samba also stops for file sharing. This kind of behaviour is normally coupled with the LAN/Wireless connection dropping, so you cannot even SSH into the machine itself.

There is no need to restart the computer, just restart the network-manager from the machine itself.

sudo service network-manager restart

mysql install from a binary distro

mysql

Installing mySQL from a binary is very simple. Download the binary to your server.

tar zxvf mysql-binary.tar.gz
cd mysql-binary
mkdir /mysql/partition/here
./configure --prefix==/mysql/partition/here
make
make install

Alternatively, even easier:

tar zxvf mysql-binary.tar.gz
cd /mysql/partition/here
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql;
cd .;
./bin/mysqladmin -uroot -pSoMePasSwOrdHeRe

tar – argument list too long

post

Found some files that you want to zip/tar up, but you’re hit with the argument list too long message? “tar – argument list too long”

The easiest way to get around this would be to use find, and output a list of those files to one solo file:

find . -type f -mtime -1 -size 100k -print > ./some-list-of-files
tar -cf allfiles.tgz –files-from ./some-list-of-files

The file “some-list-of-files” will print every file into a list, and then tar all the files within that list.

This will be the only post on my…

windows

This will be the only post on my blog about Windows Vista; I promise…!

As much as I can’t stand using any Windows machine anymore; sometimes being the only Technical person in an office can mean you need to do some Support work. My colleague had a problem with her computer (Windows Vista, HP Pavilion dv6700) where after a meeting her internet connection dropped out, she had the trusty “blue screen of death” and then was unable to reconnect to the internet when back in the office.

Have you ever tried navigating an Operating System in Japanese when you can’t read Japanese?! It really doesn’t matter how familiar you are with the positioning of the icons and tools in Windows Vista, it’s an absolute nightmare.

I’d tried all the usual things I would normally try, but nothing seemed to work. Checked all the automatic DHCP settings in Windows, tried manually removing and updating the Windows wireless drivers, flashed the BIOS; nothing was working.

Somehow, I stumbled across an error somewhere in the Network Sharing and Internet connections tool, the error had some Japanese and then in English said:

Component GUID:{7071ECA3-663B-4BC1-A1FA-B97F3B917C55}
Component file: [C:\Windows\system32\connect.dll]
Error: (0x8007277B) .

Additional Info:
Failed to detect Internet connectivity

A bit vague, I thought, but that little message at the bottom would later bare fruit as I pumped it into Google and found a solution.

1) Loading Command Prompt from Start, Programs, Accessories in Windows. Right click and then select “Open as Administrator”

2) Reset WINSOCK entries to installation defaults: netsh winsock reset catalog

3) Reset IPv4 TCP/IP stack to installation defaults. netsh int ipv4 reset reset.log

4) Reset IPv6 TCP/IP stack to installation defaults. netsh int ipv6 reset reset.log

5) Reboot

Then all was well and fixed. Phew 🙂