linux - Using expect in Perl with system() -


i trying use expect using system calls in perl script recursively create directories on remote server. relevant call follows:

system("expect -c 'spawn  ssh  $username\@$ip; expect '*?assword:*' {send \"$password\r\"}; expect '*?*' {send \"mkdir -p ~/$remote_start_folder/$remote_folder_name/$remote_username/$remote_date/\r\"}; expect '*?*' {send \"exit\r\"};  interact;'"); 

this works fine. however, if first time remote amchine accessed using ssh, asks (yes/no) confirmation. don't know add in above statement. there way incorporate above statement(using sort of or-ing)?

add yes/no match same invocation of expect password match:

expect '*yes/no*' {send "yes\r"; exp_continue;} '*?assword:*' {send \"$password\r\"}; 

this both matches, if yes/no encountered exp_continue tells expect keep looking password prompt.

full example:

system( qq{expect -c 'spawn  ssh  $username\@$ip; expect '*yes/no*' {send "yes\r"; exp_continue;} '*?assword:*' {send "$password\r"}; expect '*?*' {send "mkdir -p ~/$remote_start_folder/$remote_folder_name/$remote_username/$remote_date/\r"}; expect '*?*' {send "exit\r"};  interact;'} ); 

i've used qq avoid having escape quotation. running command shell -d flag shows expect looking either match:

password:  expect: "...\r\n\r\npassword: " (spawn_id exp4) match glob pattern     "*yes/no*"? no     "*?assword:*"? yes 

with yes/no prompt:

expect: "...continue connecting (yes/no)? " (spawn_id exp4) match glob pattern     "*yes/no*"? yes ... send: sending "yes\r" { exp4 } expect: continuing expect ... expect: "...\r\npassword: " (spawn_id exp4) match glob pattern     "*yes/no*"? no     "*?assword:*"? yes ... send: sending "password\r" { exp4 } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -