shell ssh登陆脚本

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

interact #########容许用户交互 ##若是不须要登陆进入交互能够忽略

expect eof"

}ssh

for ip in $ip do ssh donespa

相关文章
相关标签/搜索