linux-tutorial/codes/shell/系统管理/控制远程服务器执行指令.sh

31 lines
538 B
Bash
Raw Normal View History

2019-10-29 18:22:19 +08:00
#!/usr/bin/expect
2019-10-15 14:17:17 +08:00
user="root"
password="root"
/usr/bin/expect << EOF
set timeout 5
spawn ssh -o "StrictHostKeyChecking no" ${user}@${host}
expect {
"yes/no)?" { send "yes\r"; exp_continue }
"password:" { send "${password}\r" }
}
expect "root*"
send "ssh-keygen -t rsa\r"
expect "Enter file in which to save the key*"
send "\r"
expect {
"(y/n)?" { send "n\r"; exp_continue }
"Enter passphrase*" { send "\r"; exp_continue }
"Enter same passphrase again:" { send "\r" }
}
expect "root*"
send "df -h\r"
expect "root*"
send "exit\r"
EOF