zoukankan      html  css  js  c++  java
  • shell脚本之通过发送带 字符串或expect脚本实现交互输入自动化

    编写shell脚本难免遇到需要交互式输入指令的步骤:

    方法一:

    # cat action.sh
    #!/bin/sh
    read -p "enter number:" no;
    read -p "enter number:" name;
    echo you have entered $no,$name;

    # sh action.sh
    enter number:chavin
    enter number:king
    you have entered chavin,king

    # echo -e "chavin king " | sh action.sh
    you have entered chavin,king

    或者

    # echo -e "chavin king " > input.data

    # cat input.data
    chavin
    king

    # sh action.sh < input.data
    you have entered chavin,king

    案例1:使用交互式自动化为用户改密码:

    # useradd chavin0101

    # echo -e "dbking588 dbking588 " | passwd chavin0101
    Changing password for user chavin0101.
    New password: Retype new password: passwd: all authentication tokens updated successfully.

    方法二:

    使用expect实现交互式任务自动化,expect工具在一般发行版中默认没有安装,需要手工安装,这里就不演示了。

  • 相关阅读:
    poj3468(A Simple Problem with Integers)线段树+树状数组
    关于JVM——JVM内存模型
    关于JVM——类加载机制
    关于JVM(二)
    关于JVM(一)
    关于LongAdder
    关于Future
    关于Fork/Join
    关于Atomic
    关于LockSupport
  • 原文地址:https://www.cnblogs.com/wcwen1990/p/7051138.html
Copyright © 2011-2022 走看看