"리눅스 expect"의 두 판 사이의 차이

5번째 줄: 5번째 줄:
* 라이선스: 퍼블릭 도메인
* 라이선스: 퍼블릭 도메인
* SSH, SFTP, SSH 작업 등 자동화 가능
* SSH, SFTP, SSH 작업 등 자동화 가능
==주요 명령어==
{| class='wikitable'
! 명령어 !! 설명
|-
| send || 문자열을 프로세스에 보냄
|-
| expect || 프로세스로 부터 특정 문자열을 기다림
|-
| spawn || 명령을 시작
|}


==예시: FTP 작업 자동화==
==예시: FTP 작업 자동화==

2016년 12월 31일 (토) 00:48 판

1 개요

리눅스 expect
  • CLI 상호작용 자동화 프로그램
  • Tcl 스크립트 언어의 확장판
  • 라이선스: 퍼블릭 도메인
  • SSH, SFTP, SSH 작업 등 자동화 가능

2 주요 명령어

명령어 설명
send 문자열을 프로세스에 보냄
expect 프로세스로 부터 특정 문자열을 기다림
spawn 명령을 시작

3 예시: FTP 작업 자동화

set timeout -1
spawn ftp $remote_server
expect "username:"
send "$my_user_id\r"
expect "password:"
send "$my_password\r"
expect "ftp>"
send "bin\r"
expect "ftp>"
send "prompt\r"
expect "ftp>"
send "mget *\r"
expect "ftp>"
send "bye\r"
expect eof

4 예시: SFTP 작업 자동화

#!/usr/bin/env expect -f
proc connect {passw} {
  expect {
    "Password:" {
      send "$passw\r"
        expect {
          "sftp*" {
            return 0
          }
        }
    }
  }
  return 1
}
set user [lindex $argv 0]
set passw [lindex $argv 1]
set host [lindex $argv 2]
set location [lindex $argv 3]
set file1 [lindex $argv 4]
set file2 [lindex $argv 5]
if { $user == "" || $passw == "" || $host == "" || $location == "" || $file1 == "" || $file2 == "" }  {
  puts "Usage: <user> <passw> <host> <location> <file1 to send> <file2 to send>\n"
  exit 1
}

spawn sftp $user@$host
set rez [connect $passw]
if { $rez == 0 } {
  send "cd $location\r"
  set timeout -1
  send "put $file2\r"
  send "put $file1\r"
  send "ls -l\r"
  send "quit\r"
  expect eof
  exit 0
}
puts "\nError connecting to server: $host, user: $user and password: $passw!\n"
exit 1

5 같이 보기

6 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}