expect脚本: [10:40:45 root@centos8 ~]#cat expect{1..3}#!/usr/bin/expectspawn ssh 10.0.0.151expect { "yes/no" { send "yes\n";exp_continue } "password" { send "123456\n" }}interact###################################################!/usr/bin/expectset ip 10.0.0.151set user rootset password 123456set timeout 10spawn ssh $user@$ipexpect { "yes/no" { send "yes\n";exp_continue } "password" { send "$password\n" }}interact###################################################!/usr/bin/expectset ip [lindex $argv 0]set user [lindex $argv 1]set password [lindex $argv 2]set timeout 10spawn ssh $user@$ipexpect { "yes/no" { send "yes\n" ;exp_continue } "password" { send "$password\n" }}expect "#" { send "useradd hha\n" }send "exit\n"expect eof#使用expect -f expect1执行脚本,或者给执行权限后./expect1执行。 shell脚本: [10:43:08 root@centos8 ~]#cat expect4#!/bin/bashnetwork=10.0.0user=rootpassword=123456iplist="151"for ID in $iplist;doip=$network.$IDexpect <<fffspawn ssh $user@$ipset timeout 3expect { "yes/no" { send "yes\n";exp_continue } "password" { send "$password\n" }}expect "#" { send "useradd hhh\n" }expect eoffffdone#使用bash expect4,或给执行权限后./expect4运行脚本 本栏目推荐文章笑死~我的博客美化脚本分享python | 小游戏 开局托儿所 自动化脚本 pyautogui【Shell基础】Bash基础与Linux三剑客分布式限流——基于Redis的Lua脚本限流实现十行python代码实现文件去重,去除重复文件的脚本Windows Server 2016 & 2019 工作站速配脚本绕过安全限制,通过cmd执行PowerShell脚本(2)速通 形式语言与自动机java项目(jar包)配置为开机自启 jar包bat脚本启动和配置为开机自启第六天:shell脚本编程基础格式规范及变量脚本 形式 主机 expect shell脚本 形式 主机expect 脚本expect shell 脚本 命令 主机expect linux-expect命令 形式expect expect shell 脚本 形式 密码 文件 脚本shell 脚本shell日志 脚本amp地址shell 编程语言 主机 语言shell