36.11 ssh远程操作
#!/usr/bin/expect
set timeout 30
spawn ssh -l username 192.168.1.1
expect "password:"
send "ispass\r"
interactLast updated
#!/usr/bin/expect
set timeout 30
spawn ssh -l username 192.168.1.1
expect "password:"
send "ispass\r"
interactLast updated
#!/bin/bash
pass=123
/usr/bin/expect <<EOF
set timeout 30
spawn scp /root/install.log 192.168.1.1:/home
expect "password:"
send "$pass\r"
expect eof
EOF#!/bin/bash
integrate_ans_zbx() {
/usr/bin/expect <<EOF
set timeout 180
spawn ssh [email protected]
expect {
"(yes/no)?" {
send "yes\r";
expect "password:";
send "${ANS_PASS}\r";
exp_continue;
}
"password:" {
send "${ANS_PASS}\r";
exp_continue;
}
"*#" {
send "sed -i '/# ${1} insert/i\ ${IP}:' ${INVENTORY_FILE}\r";
send "sed -i 's/${IP}/ ${IP}/g' ${INVENTORY_FILE}\r";
send " ansible-playbook -i ${INVENTORY_FILE} ${ZABBIX_PALYBOOK_FILE} \
-l ${IP} --skip-tags 'sangoma,debian,suse,windows,docker'\r";
}
}
expect eof
EOF
}
main() {
update_ssh
integrate_jms "$@"
integrate_ans_zbx "$@"
}
main "$@"