Created
September 1, 2011 08:34
-
-
Save Govan/1185721 to your computer and use it in GitHub Desktop.
Tunnels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
ssh -nNT -R 1100:localhost:22 fake-remote.leftbrained.co.uk -p 2712 -i /Users/gavin/Dropbox/bin/reverse-tunnel.d/tunnel-key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null | |
# Script above opens a reverse tunnel from laptop to fake-remote.leftbrained.co.uk | |
# from fake-remote.leftbrained.co.uk (a VPS I use for general cruft work) I can do... | |
$ ssh localhost -p1100 | |
# That uses the outbound tunnel from laptop to fake-remote to go from fake-remote to laptop. | |
# On the laptop, the following runs every few minutes. It picks up email from | |
# a super-secret account and picks an applescript to run, one of which opens the tunnel. | |
require 'rubygems' | |
require 'logger' | |
require "net/imap" | |
username = 'XXXXX@XXXX.com' | |
password = 'XXXXXX' | |
command_dir = File.join(File.dirname(__FILE__), 'command_scripts') | |
logger = Logger.new(File.join(File.dirname(__FILE__), "log/commands.log")) | |
Gmail.new(username, password) do |gmail| | |
gmail.inbox.emails(:from => "XXXXXX@XXXXX.com").each do |email| | |
# Build the command | |
logger.info "=========================" | |
logger.info email.subject | |
the_service = email.subject.strip.split(" ").first.downcase | |
the_command = email.subject.strip.split(" ").last.downcase | |
full_service_script_path = File.join(command_dir, the_service+".scpt") | |
# Run the command, if we have a script for it. | |
logger.info "Executing #{full_service_script_path}" | |
system("osascript "+full_service_script_path+" "+the_command) if File.exists? full_service_script_path | |
email.delete! | |
end | |
#end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment