【expect】用expect实现scp/ssh-copy-id的非交互

# 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

"

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

【expect】用expect实现scp/ssh-copy-id的非交互_第1张图片

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

你可能感兴趣的:(【expect】用expect实现scp/ssh-copy-id的非交互)