Skip to content

Instantly share code, notes, and snippets.

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

@vicgc
vicgc / noise.sh
Created July 7, 2014 08:24 — forked from rsvp/noise.sh
#!/usr/bin/env bash
# bash 4.1.5(1) Linux Ubuntu 10.04 Date : 2011-10-04
#
# _______________| noise : ambient Brown noise generator (cf. white noise).
#
# Usage: noise [minutes=59] [band-pass freq center=1786] [wave]
# ^minutes can be any positive integer.
# Command "noise 1" will display peak-level meter.
#
# Dependencies: play (from sox package)
def compute_check_digit(str)
str = str.strip.upcase
values = str.chars.map do |char|
case char
when '<'
0
when 'A'..'Z'
char.ord - 65 + 10
when '0'..'9'
char.ord - 48
import glob
import sys
import os
import sqlite3 as sqlite
def LoadScripts(scriptFolder):
''' Returns a list of module references '''
# Find Script Files:
scriptFiles = glob.glob(os.path.join(scriptFolder, "Script*.py"))
print "Found %d Script Files" % (len(scriptFiles))
# <author>Pieter Muller</author>
# <date>2013-03-05</date>
# <note>Targets Python 2.7</note>
import sqlite3 as sqlite
import sys
if __name__ == "__main__":
if (len(sys.argv) != 3):
print "\n\tRequires two arguments:"
# <author>Pieter Muller</author>
# <date>2012-11-14</date>
import sys
import sqlite3 as sqlite
tablesToIgnore = ["sqlite_sequence"]
outputFilename = None
#!/bin/bash
#Converts images to text using tesseract (package tesseract-ocr & tesseract-ocr-eng)
function usage
{
echo "img2txt -i <input directory> -o <output directory> --concat"
}
function concat
{
#The MIT License (MIT)
# Copyright (c) 2012 Jordan Wright <jordan-wright.github.io>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
import luigi
class ATask(luigi.Task):
def output(self):
return luigi.LocalTarget("atask_output.txt")
def run(self):
with self.output().open("w") as outfile:
outfile.write("Test")
#!/usr/bin/env python
# This script is like generate_image.py from the OSM Mapnik code,
# but it renders based on a given centre point, zoom and final image pixel size
# Author: Andrew Harvey <andrew.harvey4@gmail.com>
# License: CC0 http://creativecommons.org/publicdomain/zero/1.0/
#
# To the extent possible under law, the person who associated CC0
# with this work has waived all copyright and related or neighboring