{"action":"opened","issue":{"url":"https://api.github.com/repos/philippkeller/rexpect/issues/5","repository_url":"https://api.github.com/repos/philippkeller/rexpect","labels_url":"https://api.github.com/repos/philippkeller/rexpect/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/philippkeller/rexpect/issues/5/comments","events_url":"https://api.github.com/repos/philippkeller/rexpect/issues/5/events","html_url":"https://github.com/philippkeller/rexpect/issues/5","id":300095626,"number":5,"title":"Need help on converting a bash script into rexpect","user":{"login":"tjyang","id":378638,"avatar_url":"https://avatars1.githubusercontent.com/u/378638?v=4","gravatar_id":"","url":"https://api.github.com/users/tjyang","html_url":"https://github.com/tjyang","followers_url":"https://api.github.com/users/tjyang/followers","following_url":"https://api.github.com/users/tjyang/following{/other_user}","gists_url":"https://api.github.com/users/tjyang/gists{/gist_id}","starred_url":"https://api.github.com/users/tjyang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjyang/subscriptions","organizations_url":"https://api.github.com/users/tjyang/orgs","repos_url":"https://api.github.com/users/tjyang/repos","events_url":"https://api.github.com/users/tjyang/events{/privacy}","received_events_url":"https://api.github.com/users/tjyang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-26T03:08:50Z","updated_at":"2018-02-26T03:08:50Z","closed_at":null,"author_association":"NONE","body":"Hi @philippkeller \r\n\r\n\r\n* And this is the command and logs from realm join command\r\n\r\n```\r\n#realm join -v --computer-ou=\"ou=servers,dc=test,dc=com\" test.com -U admin_ad\r\n * Resolving: _ldap._tcp.test.com\r\n * Performing LDAP DSE lookup on: 100.76.1.18\r\n * Performing LDAP DSE lookup on: 100.76.1.19\r\n * Performing LDAP DSE lookup on: 100.64.0.65\r\n * Successfully discovered: test.com\r\nPassword for admin_ad: admin_ad_password\r\n```\r\n\r\n* This is one-liner  bash script I used to join a centos 7 to MS AD domain.\r\n\r\n```\r\nrealm join -v --computer-ou=\"ou=ma,ou=servers,dc=test,dc=com\" test.com -U admin_ad << MYPASSWD\r\nadmin_ad_password\r\nMYPASSWD\r\n```\r\n\r\n* And this is using rexpect 0.3\r\n\r\n```\r\n//Run this code with cargo\r\n// Join test.com AD domain on CentOS 7 with SSSD enabled.\r\n//  Following is the response from realm command\r\n//!  realm join -v --computer-ou=\"ou=unit1,ou=servers,dc=test,dc=com\" test.com -U admin_ad\r\n//!  * Resolving: _ldap._tcp.test.com\r\n//!  * Performing LDAP DSE lookup on: 100.76.1.18\r\n//!  * Performing LDAP DSE lookup on: 100.76.1.19\r\n//!  * Performing LDAP DSE lookup on: 100.58.0.65\r\n//!  * Successfully discovered: test.com\r\n//! Password for admin_ad:\r\n\r\nextern crate rexpect;\r\n\r\nuse rexpect::spawn;\r\nuse rexpect::errors::*;\r\n\r\nfn  join() -> Result<()> {\r\n    let mut p = spawn(\"realm join -v --computer-ou=\\\"ou=ma,ou=servers,dc=test,dc=com\\\" test.com -U admin_ad\", Some(30_000))?;\r\n    p.exp_regex(\"^Password for .*: \")?;\r\n    p.send_line(\"admin_ad_password\")?;\r\n    p.exp_eof()?;\r\n    Ok(())\r\n}\r\n\r\n\r\nfn main() {\r\n    join().unwrap_or_else(|e| panic!(\"Failed to joing test.com AD domain {}\", e));\r\n\r\n```\r\n\r\n* The error \r\nIs there a way to skip first 5 lines from realm command output ? \r\n\r\n```\r\n>target/debug/joinad\r\nthread 'main ' panicked at 'Failed to joing test.com AD domain EOF (End of File): Expected Regex: \"^Password for .*: \" but got EOF after reading \" * Resolving: _ldap._tcp.test.com\r\n```\r\n*  I inserted \"p.wait_for_prompt()?;\" before \" p.exp_regex\" but I got compilation error saying no wait_for_promp method for ptysession ..."}}
{"actor":{"display_login":"tjyang"}}