Operating System

expect 명령어를 이용하여 rsync auto script 구현

나크나로·2017년 9월 26일·조회 6,291

1. rsync 설치

당연히 rsync가 설치되어 있어야 한다.


2. 일반적인 사용

rsync -avz -e "ssh -p 22" ip.sh testuser@192.168.1.10:/test/

password: 라면서 패스워드를 물어보게 된다.


3. expect 활용

expect <<EOF
spawn rsync -avz -e "ssh -p 22" ip.sh testuser@192.168.1.10:/test/
expect "password:"
send "passpass\r"
expect eof
EOF

- 결과

# rsync_test.sh
spawn rsync -avz -e ssh -p 22 ip.sh testuser@192.168.1.10:/test/
testuser@192.168.1.10's password:
sending incremental file list
testfile.txt

sent 224 bytes  received 31 bytes  510.00 bytes/sec
total size is 213  speedup is 0.84

4. 오류

"ssh -p 22" 를 'ssh -p 22' 와 같이 Single Quotation으로 사용하면 오류 발생

- 결과

# rsync_test.sh
spawn rsync -avz -e 'ssh -p 22' ip.sh testuser@192.168.1.10:/test/
Missing trailing-' in remote-shell command.
rsync error: syntax or usage error (code 1) at main.c(361) [sender=3.0.6]
send: spawn id exp4 not open
    while executing
"send "passpass\r""

댓글 0

로그인 후 댓글을 남길 수 있습니다.

아직 댓글이 없습니다.