shell ssh login script

Expect Small knowledge Characters that need to be escaped\ need to be escaped as \
} need to be escaped as } [ need to be escaped as [ $ need to be escaped as \$ 需转义为 \" need to be escaped as \" #!/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"

interact #########Allow user interaction##If you don't need to log in to enter the interaction, you can ignore it

expect eof"

}

for ip in $ip do ssh done

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325456998&siteId=291194637