expect의 간단한 사용기


#!/usr/bin/expect -f


set target "[lindex $argv 0]"


spawn rsync -a -e ssh /usr/local/ant/ root@$target:/usr/local/ant/

expect -timeout 5  "*assword:"

send "root비밀번호\n"

sleep 2


expect eof


보통 rsync로 파일을 복사할때 위의 명령어를 실행하면 비밀번호를 물어보지만
expect에 걸린 저 내용에 send의 설정된 비밀번호를 자동으로 입력해줌

ssh key없이도 파일 복사가 가능

해당 스크립트 언어로 여러가지 자동화 작업을 가능하게 할수있음 

간단하게 메크로같은 기능임


'IT Study > script' 카테고리의 다른 글

linux server default dependencies install  (0) 2016.05.09
server default configure script  (0) 2016.05.09
file create shell scripts  (0) 2016.03.04
mysql schema backup scripts  (0) 2016.02.19
mysql table backup scripts  (0) 2016.02.19

+ Recent posts