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