如何在SSM文档的Shell脚本中自动回应apt autoremove的Y确认?
解决apt autoremove自动确认的问题
你尝试用<<- Y自动回应确认提示无效,是因为这是Shell的here-doc语法,不适合处理这类交互式命令的确认请求。可以用以下两种方法解决:
方法1:使用apt自带的自动确认参数
apt命令本身提供-y参数,会自动确认所有交互式提示,直接修改命令即可:
schemaVersion: "2.2" description: "Command Document Example JSON Template" parameters: Message: type: "String" description: "Hello World!" default: "Hello" mainSteps: - action: "aws:runShellScript" name: "HelloScript" inputs: runCommand: - "sudo apt autoremove nessusagent -y &&" - "sleep 20 &&" - "echo 'uninstallation completed!'"
方法2:用yes命令管道输入
如果场景特殊无法使用-y参数,可通过yes命令持续输出Y,通过管道传递给apt命令:
schemaVersion: "2.2" description: "Command Document Example JSON Template" parameters: Message: type: "String" description: "Hello World!" default: "Hello" mainSteps: - action: "aws:runShellScript" name: "HelloScript" inputs: runCommand: - "yes | sudo apt autoremove nessusagent &&" - "sleep 20 &&" - "echo 'uninstallation completed!'"
推荐优先使用方法1,这是apt官方支持的自动确认方式,逻辑更清晰,也避免了不必要的输出。
内容的提问来源于stack exchange,提问作者Sai Teja Makani
相关产品推荐
相关产品推荐

