expect 小知识 须要转义的字符 \ 需转义为 \
} 需转义为 } [ 需转义为 [ $ 需转义为 \$ 需转义为 \
" 需转义为 \" #!/bin/bash user='root' password_dir=/mnt #cmd="echo 'hahah' > /mnt/test.txt" ip=cat $password_dir/password.txt|awk '{print $1}'
password=grep $ip password.txt |awk '{print $2}'
ssh() { expect -c " set timout 60
spawn ssh $user@$ip expect { "yes/no" {send "yes\r";exp_continue;} "assword:" {send $password\r;} } expect
sleep 10 expect "]" send "echo 'hahah' > /mnt/test.txt\r"bash
expect eof"
}ssh
for ip in $ip do ssh donespa