【expect】用expect實現scp/ssh-copy-id的非互動

weixin_34248705發表於2018-07-10

# cat expect.sh 

###################

#!/bin/bash

ip=192.168.1.105

pwd="123456"

rm -f  ~/.ssh/id_rsa

rm -f  ~/.ssh/id_rsa.pub

ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa

expect -c "

  set timeout 10

  spawn ssh-copy-id root@${ip}

  expect {

  *yes/no* {send "yes"\r;exp_continue;}

  *assword* {send "${pwd}"\r;}

}

  expect -re \](\$|#)

  exit

"

############################

12979420-c475efae3c5bbaa6

http://www.cnblogs.com/f-ck-need-u/p/7542210.html

相關文章