预期交互

Posted ray-mmss

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了预期交互相关的知识,希望对你有一定的参考价值。

拷贝密钥

#!/bin/bash

read -p "server ip:" ip
read -p "server pwd:" pwd

expect << EOF
spawn ssh-copy-id [email protected]$ip 
expect "(yes/no)" {send "yes
"}
expect "password:" {send "$pwd
"}
expect "#" {send "exit
"}
EOF
echo ‘‘

为新安装的mysql设置密码策略及密码

#!/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
"}
expect "> " {send "set global validate_password_policy=0;
"}
expect "> " {send "set global validate_password_length=6;
"}
expect "> " {send alter user user() identified by "$pwd";
}
expect "#" {send "exit
"}
EOF
echo ‘‘

 

为新建的虚拟设置ip及主机名

#!/bin/bash
read -p "请输入hostname:" name
read -p "请输入ip :" ip
read -p "请输入要连接的虚拟机:" vm

expect <<  EOF
spawn virsh console $vm
expect " " {send "
"}
expect ":" {send "root
"}
expect "" {send "123456
"}
expect "#" {send "hostnamectl set-hostname $name
"}
expect "#" {send "hostname $name
"}
expect "#" {send "nmcli connection modify eth0 ipv4.method manual ipv4.addresses $ip/24 connection.autoconnect yes
"}
expect "#" {send "nmcli connection up eth0
"}
expect "#" {send "exit
"}
EOF
echo ‘‘

 

以上是关于预期交互的主要内容,如果未能解决你的问题,请参考以下文章

片段中预期的方法调用

如何在不与 MainActivity 交互的情况下从通知中打开片段页面?

Selenium 预期条件,等到元素可交互?

前端防扒代码片段

前端防扒代码片段

前端防扒代码片段