[ruby] expect
ruby에서 마땅한 expect 가 없었던 것 같다. (ruby 지인은 bin/expect를 활용하는 방식을 주로 사용했다고 한다.) 함 찾아보고 안되면 bin/expect 쓰려했는데, 적당히 쓸만한 오픈소스를 발견했다.
https://github.com/abates/ruby_expect 의 expect를 써봤는데, 쓸만하다. ruby expect 를 원하는 분들에게 희소식일듯 하다.
나는 최신 버전을 사용하고 간단하게 require_relative를 쓰는 것을 좋아해서https://github.com/abates/ruby_expect 의 ruby 소스 두개를 하나로 merge해서 ruby 하나 파일로 만들었다. https://github.com/knight1128/ruby-expect
사용법
$ wget https://raw.githubusercontent.com/knight1128/ruby-expect/master/expect.rb
$ vi test.rb
require_relative 'expect'
DB_USER_NAME = "www"
DB_USER_PWD = "wwwteam"
mysql_version = `mysql --version | tr [,] ' ' | tr [:space:] '\n' | grep -E '([0-9]{1,3}[\.]){2}[0-9]{1,3}'`
if mysql_version > "5.6.0"
SUPPORT_MYSQL_5DOT6 = true
else
SUPPORT_MYSQL_5DOT6 = false
end
if SUPPORT_MYSQL_5DOT6
exp = RubyExpect::Expect.spawn("mysql_config_editor set --login-path=localhost --host=localhost --user=#{DB_USER_NAME} --password")
exp.procedure do
each do
expect /Enter password:/ do
send DB_USER_PWD
end
end
end
end