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

相關文章
相關標籤/搜索