#!/bin/bash read -p "server ip:" ip read -p "server pwd:" pwd expect << EOF spawn ssh-copy-id root@$ip expect "(yes/no)" {send "yes\r"} expect "password:" {send "$pwd\r"} expect "#" {send "exit\r"} EOF echo ‘‘
#!/bin/bash read -p ‘set pwd:‘ pwd temp=`awk -F: ‘/localhost/{print $4}‘ /var/log/mysqld.log | awk ‘{print $1}‘` expect << EOF spawn mysql -uroot -p expect ":" {send "$temp\r"} expect "> " {send "set global validate_password_policy=0;\r"} expect "> " {send "set global validate_password_length=6;\r"} expect "> " {send ‘alter user user() identified by "$pwd";\r‘} expect "#" {send "exit\r"} EOF echo ‘‘
#!/bin/bash read -p "请输入hostname:" name read -p "请输入ip :" ip read -p "请输入要连接的虚拟机:" vm expect << EOF spawn virsh console $vm expect " " {send "\r"} expect ":" {send "root\r"} expect ":" {send "123456\r"} expect "#" {send "hostnamectl set-hostname $name\r"} expect "#" {send "hostname $name\r"} expect "#" {send "nmcli connection modify eth0 ipv4.method manual ipv4.addresses $ip/24 connection.autoconnect yes\r"} expect "#" {send "nmcli connection up eth0\r"} expect "#" {send "exit\r"} EOF echo ‘‘
原文:https://www.cnblogs.com/ray-mmss/p/10329235.html