Skip to content

Instantly share code, notes, and snippets.

View athaller's full-sized avatar
💭
Making Magic

athaller

💭
Making Magic
  • $date :: PHP :: Systems :: Dev Ops
  • East :: Web
View GitHub Profile

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@athaller
athaller / 0_reuse_code.js
Created March 18, 2016 18:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@athaller
athaller / plwatch.sh
Created March 17, 2016 14:45 — forked from lrq3000/plwatch.sh
A simple bash script to watch packets loss using ping on Unix/Linux
#!/bin/bash
# Packets Loss Watch
# Simple SHELL script for Linux and UNIX system monitoring with
# ping command
#
# Copyright (c) 2006 nixCraft project <http://www.cyberciti.biz/fb/>
# Copyleft 2013 Stephen Larroque
# This script is licensed under GNU GPL version 2.0 or above
#
# This script was inspired by a nixCraft script http://www.cyberciti.biz/tips/simple-linux-and-unix-system-monitoring-with-ping-command-and-scripts.html
#!/bin/bash
sudo apt-get update
sudo apt-get -y install python-setuptools python-dev libffi-dev libssl-dev git sshpass
sudo easy_install pip
sudo -H pip uninstall -y virtualenv
sudo -H pip uninstall -y virtualenvwrapper
sudo -H pip install virtualenv
sudo -H pip install virtualenvwrapper --ignore-installed six
sudo -H pip install httplib2
@athaller
athaller / build
Created January 22, 2016 17:37
aegir platform build/import script
#!/bin/sh
############################################################
# Aegir build script #
# Builds a platform from a supplied Drush make stub file #
# and saves/imports it into an Aegir system #
# #
# Written by Miguel Jacq (mig5) of Green Bee Digital #
# February 2011 #
############################################################
<?php
$aliases['server_clusterwebmig5net'] = array (
'context_type' => 'server',
'server' => '@server_master',
'remote_host' => 'cluster-web.mig5.net',
'aegir_root' => '/var/aegir',
'script_user' => 'aegir',
'ip_addresses' =>
array (
0 => '106.187.40.34',
@athaller
athaller / vcloud-vm-lookup.sh
Created January 22, 2016 17:36 — forked from mig5/vcloud-vm-lookup.sh
vcloud-vm-lookup
#!/bin/bash
usage() {
cat << EOF
usage: $0 ARGUMENTS
Simple wrapper script to query the vCloud API and return a
YAML object of a specific virtual machine.
Written by mig5 July 2014
@athaller
athaller / gist:3a03e14eacbac028ef36
Created January 22, 2016 17:35 — forked from mig5/gist:a89af7d113f403521cd7
Bring Vagrant VM up if it's off and you tried to vagrant ssh
vagrant() {
if [[ $@ == "ssh" ]]; then
command vagrant ssh || command vagrant up && command vagrant ssh
else
command vagrant $@
fi
}
@athaller
athaller / Vagrantfile
Created January 13, 2016 04:54 — forked from jbgo/Vagrantfile
Getting started with ansible on OS X
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :private_network, ip: "192.168.33.10"
config.ssh.forward_agent = true
#!/bin/sh
BOOT2DOCKER_CERTS_DIR=/var/lib/boot2docker/certs
CERTS_DIR=/etc/ssl/certs
CAFILE=${CERTS_DIR}/ca-certificates.crt
for cert in $(/bin/ls -1 ${BOOT2DOCKER_CERTS_DIR}); do
SRC_CERT_FILE=${BOOT2DOCKER_CERTS_DIR}/${cert}
CERT_FILE=${CERTS_DIR}/${cert}
HASH_FILE=${CERTS_DIR}/$(/usr/local/bin/openssl x509 -noout -hash -in ${SRC_CERT_FILE} 2>/dev/null)