Created
November 1, 2012 21:23
-
-
Save imagescape/3996676 to your computer and use it in GitHub Desktop.
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
#!/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