--Boundary-00=_wBl99GHIfGu1mM1
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi Noah,
I've been using a bash/expect [1] script to detect and mount my
encrypted file partions before syncing them with unison [2].
However, for some reason it hasn't been working properly
and I shuddered to consider returning to trying to understand
expect. I rewrote the script in pexpect very quickly and I'm
very happy with it, thanks!
[1]
http://expect.nist.gov/
[2]
http://www.cis.upenn.edu/~bcpierce/unison/
[3]
http://pexpect.sourceforge.net/
--Boundary-00=_wBl99GHIfGu1mM1
Content-Type: text/x-python;
charset="us-ascii";
name="sb.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="sb.py"
#! /usr/bin/env python
def TestPartitions():
import commands, getpass
ssh=None
password=None
# if not os.access("/home/reagle/data/1work/", os.R_OK):
if commands.getstatusoutput('test -d $HOME/data/1work; pmount=$?; echo $pmount')[1] == '1':
password = getpass.getpass("Password: ")
MountPartition(password,ssh)
else: print "Local already mounted"
if commands.getstatusoutput('ssh flux test -d $HOME/data/1work; pmount=$?; echo $pmount')[1] == '1':
ssh=1
if not password: password = getpass.getpass("Password: ")
MountPartition(password,ssh)
else: print "Remote already mounted"
def MountPartition(password,ssh):
import os, pexpect, sys
if not ssh:
print "Mounting LOCALLY"
child = pexpect.spawn('bctool mount -t ext3 /e/work-policy /home/reagle/data')
else:
print "Mounting REMOTELY"
child = pexpect.spawn('ssh flux.w3.org bctool mount -t ext3 /e/work-flux /home/reagle/data')
child.expect('Enter password:', 2)
print "Sending password"
child.sendline (password)
result = child.expect(['.*Password incorrect','WARNING! Container.*',pexpect.EOF])
if result == 0:
print "Password incorrect"
elif result == 1:
print "Warning, the container is probably already in use"
elif result == 2:
print "Successfully mounted"
else:
print "Exited in unknown state"
#Check to see if the script is executing as main.
if __name__ == "__main__":
## Parse the command line arguments for optional message and files.
TestPartitions()
--Boundary-00=_wBl99GHIfGu1mM1--