SHELL脚本编程-expect

                       作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

 

一.expect概述

1>.expect介绍

  expect 是由Don Libes基于Tcl( Tool Command Language )语言开发的,主要应用于自动化交互式操作的场景,借助Expect处理交互的命令,可以将交互过程如:ssh登录,ftp登录等写在一个脚本上,使之自动化完成。尤其适用于需要对多台服务器执行相同操作的环境中,可以大大提高系统管理人员的工作效率。

2>.expect命令

expect 语法:
  expect [选项] [ -c cmds ] [ [ -[f|b] ] cmdfile ] [ args ]

常用选项   
-c:从命令行执行expect脚本,默认expect是交互地执行的     示例:expect -c 'expect "\n" {send "pressed enter\n"}   -d:可以输出输出调试信息     示例:expect -d ssh.exp
expect中相关命令   spawn:
    启动新的进程   send:
    用于向进程发送字符串   expect:
    从进程接收字符串   interact:
    允许用户交互   exp_continue
    匹配多个字符串在执行动作后加此命令

3>.安装expect软件包

[root@node101.yinzhengjie.org.cn ~]# yum info expect
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.aliyun.com
Available Packages
Name        : expect
Arch        : x86_64
Version     : 5.45
Release     : 14.el7_1
Size        : 262 k
Repo        : base/7/x86_64
Summary     : A program-script interaction and testing utility
URL         : http://expect.nist.gov/
License     : Public Domain
Description : Expect is a tcl application for automating and testing
            : interactive applications such as telnet, ftp, passwd, fsck,
            : rlogin, tip, etc. Expect makes it easy for a script to
            : control another program and interact with it.
            : 
            : This package contains expect and some scripts that use it.

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# yum info expect      #查看expect软件包相关信息

相关文章:

  • 2022-12-23
  • 2021-12-25
  • 2018-09-15
  • 2022-01-25
猜你喜欢
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2021-11-20
  • 2021-08-14
  • 2021-12-14
相关资源
相似解决方案