LoginSignup
0
0

More than 5 years have passed since last update.

pexpect, Expect.pm

Posted at

手元から適当なサーバに rsync する例

Expect.pm

sample.pl
#!/usr/bin/env perl
use strict ;
use warnings ;
use Expect
my $command = join " ",
    '/usr/bin/rsync -aqz',
    '/PATH/TO/from/',
    'foo@example.com:/PATH/TO/to/'
    ;
my $obj = new Expect;
$obj->spawn($command);
$obj->expect(1,$command);
$obj->send("PASSWD\n");
$obj->interact;
$obj->soft_close();
$ perl sample.pl

pexpect

インストールは手軽。

python2.6 で適当なローカルディレクトリに入れたもの。

$ pip install --install-option="--prefix=/PATH/TO" pexpect
sample.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.path.append( '/PATH/TO/lib/python2.6/site-packages')
import pexpect
command = " ".join([
    '/usr/bin/rsync -aqz',
    '/PATH/TO/from/',
    'foo@example.com:/PATH/TO/to/'
])
cmd = pexpect.spawn(command)
cmd.logfile = sys.stdout
cmd.expect(".assword:*")
cmd.sendline("PASSWD")
cmd.interact()

しかし、cron に乗っけようとすると mode = tty.tcgetattr(self.STDIN_FILENO) あたりでエラーになる。
回避方法もありそうな気もするが、perl 版の方は動くし、追いかける気もしないので、使わない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0