[Assorted-commits] SF.net SVN: assorted:[1128] shell-tools/trunk
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-01-12 06:35:32
|
Revision: 1128 http://assorted.svn.sourceforge.net/assorted/?rev=1128&view=rev Author: yangzhang Date: 2009-01-12 06:35:21 +0000 (Mon, 12 Jan 2009) Log Message: ----------- added mssh; tweaked env vars; updated mkcdbs Modified Paths: -------------- shell-tools/trunk/README shell-tools/trunk/src/bash-commons/bashrc.bash shell-tools/trunk/src/bash-commons/common.bash Added Paths: ----------- shell-tools/trunk/src/mssh.py Modified: shell-tools/trunk/README =================================================================== --- shell-tools/trunk/README 2009-01-09 08:43:53 UTC (rev 1127) +++ shell-tools/trunk/README 2009-01-12 06:35:21 UTC (rev 1128) @@ -101,10 +101,16 @@ `bootstrap- Fetch, build, and install cabal. bash, ghc6 cabal` + +`mssh` Run ssh commands on multiple hosts Python, + (sequentially), but also be able to enter a [Pexpect] + common password (useful when keys aren't set + up. -------------------------------------------------------------------------------- [HSH]: http://software.complete.org/hsh/ [Python Commons]: http://assorted.sf.net/python-commons/ +[Pexpect]: http://pexpect.sf.net/ Usage ----- Modified: shell-tools/trunk/src/bash-commons/bashrc.bash =================================================================== --- shell-tools/trunk/src/bash-commons/bashrc.bash 2009-01-09 08:43:53 UTC (rev 1127) +++ shell-tools/trunk/src/bash-commons/bashrc.bash 2009-01-12 06:35:21 UTC (rev 1128) @@ -32,7 +32,8 @@ ################################################################ # personal environment variables (TODO somehow factor this out) -export EMAIL='Yang Zhang <y_...@mi...>' +export EMAIL='Yang Zhang <ya...@gm...>' +export DEBEMAIL='ya...@gm...' # TODO this is from sht; mv it to a mini-commons # TODO is this necessary in light of advanced var expansions? Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2009-01-09 08:43:53 UTC (rev 1127) +++ shell-tools/trunk/src/bash-commons/common.bash 2009-01-12 06:35:21 UTC (rev 1128) @@ -513,9 +513,17 @@ mv "$path" "${path%.*}" } +# Set up a new Debian CDBS package but remove all the boilerplate cruft and +# tweak the files. mkcdbs() { - echo -e 'b\n\n' | dh_make --createorig + local flags= pkg="$(basename "${PWD%-*}")" ver="${PWD##*-}" + if [[ ! -d ../$pkg-$ver.orig && ! -f ../${pkg}_$ver.orig.tar.gz ]] + then flags=--createorig + fi + echo | dh_make --cdbs --copyright gpl $flags rm debian/{dirs,docs,README*,*.ex,*.EX} + sed -i 's/-1) unstable;/-1ubuntu1) intrepid;/' debian/changelog + sed -i 's/Standards-Version: .*/Standards-Version: 3.8.0/' debian/control } #if ! is_declared indent ; then Added: shell-tools/trunk/src/mssh.py =================================================================== --- shell-tools/trunk/src/mssh.py (rev 0) +++ shell-tools/trunk/src/mssh.py 2009-01-12 06:35:21 UTC (rev 1128) @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +""" +Run ssh commands on multiple hosts (sequentially), but also be able to take a +password and forward it on to each of the hosts. This is useful when SSH keys +are not set up on the hosts. The hosts that you log into are read from the +`hosts` environment variable. Examples of invocation: + + hosts='farm2 farm3 farm4' mssh -l root 'usermod -a -G admin yang' + hosts='farm2 farm3 farm4' mssh -l root 'echo ... >> .ssh/authorized_keys' + +This is also a nice, simple demo of how tty/pty stuff works. +""" + +import getpass, os, pexpect, sys, time +passwd = getpass.getpass("Password: ", open("/dev/tty", "w", 0)) +try: + for host in os.getenv("hosts").split(): + child = pexpect.spawn("ssh", [host] + sys.argv[1:]) + child.expect("password: ") + child.sendline(passwd) + try: + child.expect("password: ") + except pexpect.EOF: # Label and show the output + print "==", host, "==", child.before + else: # Actually got prompted for password again + child.sendcontrol("c") + try: child.read() + except pexpect.EOF: pass + raise Exception("bad passwd") + finally: + if child.isalive(): child.wait() +except Exception, ex: + print >> sys.stderr, ex Property changes on: shell-tools/trunk/src/mssh.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |