V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
15079060090
V2EX  ›  Linux

执行 shell 脚本时,遇到需要输入 yes/no 的时候,怎么自动化完成输入呢?(小白求教!)

  •  
  •   15079060090 · 2019-01-09 14:37:48 +08:00 · 4911 次点击
    这是一个创建于 1906 天前的主题,其中的信息可能已经有所发展或是发生改变。

    export ORACLE_SID=SMTCWHDB

    rman target /

    DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-5';

    yes or no

    crosscheck archivelog all;

    delete expired archivelog all;

    exit

    在执行这个 sheel 到了第四句时候 要输入 yes 回车 怎么写?

    8 条回复    2019-01-09 19:27:32 +08:00
    alexsunxl
        1
    alexsunxl  
       2019-01-09 14:43:36 +08:00
    yes | 要回到的命令

    ----------
    可以 man yes 看具体
    alexsunxl
        2
    alexsunxl  
       2019-01-09 14:43:56 +08:00
    @alexsunxl
    yes | 需要回答的命令
    fo2w
        3
    fo2w  
       2019-01-09 14:45:01 +08:00   ❤️ 1
    expect script
    shylockhg
        4
    shylockhg  
       2019-01-09 14:50:21 +08:00
    printf
    echo
    etc.
    管道默认就是 STDIO
    www5070504
        5
    www5070504  
       2019-01-09 15:02:10 +08:00
    刚试了下 这个 yes 命令还真是。。。
    ZXCDFGTYU
        6
    ZXCDFGTYU  
       2019-01-09 15:06:12 +08:00
    yes | 命令
    crazypig14
        7
    crazypig14  
       2019-01-09 15:07:54 +08:00
    expect + spawn,不过这里 yes 就够了
    Gempty
        8
    Gempty  
       2019-01-09 19:27:32 +08:00
    @ZXCDFGTYU +1 正解
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5393 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 06:57 · PVG 14:57 · LAX 23:57 · JFK 02:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.