Skip to content

Instantly share code, notes, and snippets.

@imagescape
Created November 1, 2012 21:23
Show Gist options
  • Save imagescape/3996676 to your computer and use it in GitHub Desktop.
Save imagescape/3996676 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os, sys, argparse, subprocess
from fabric.api import *
def get_args():
parser = argparse.ArgumentParser(description='Run bash commands on a remote host. Get notified when its done.')
parser.add_argument('hoststring', type=str, nargs=1,
help='ssh user@host string')
parser.add_argument('commandstring', type=str, nargs=1,
help='string of commands to run')
return parser.parse_args()
done_sound = os.environ.get('NOTIFY_SOUND', None)
error_sound = os.environ.get('NOTIFY_ERROR_SOUND', done_sound)
if "__main__" == __name__:
args = get_args()
env.host_string = args.hoststring[0]
with settings(warn_only=True):
retval = run(args.commandstring[0])
if retval.succeeded:
notify = subprocess.Popen(("notify-send", args.hoststring[0], args.commandstring[0]))
if done_sound:
retval = subprocess.Popen(("playsound", done_sound))
else:
notify = subprocess.Popen(("notify-send", "FAILED: %s" % args.hoststring[0], args.commandstring[0]))
if error_sound:
retval = subprocess.Popen(("playsound", error_sound))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment