请问shell脚本如何绕过yes/no确认?

请问shell脚本如何绕过yes/no确认?试了几种方法,不知道哪种正确。

[tidb@monitor ~]$ tiup br log truncate --until=${keep_full_backup_ts} --storage=‘/backup/tidb/log’

A new version of br is available: v8.3.0 → v8.5.0

To update this component:   tiup update br
To update all components:   tiup update --all

Starting component br: /home/tidb/.tiup/components/br/v8.3.0/br log truncate --until=454892409444106241 --storage=/backup/tidb/log
Detail BR log in /tmp/br.log.2024-12-26T16.08.19+0800
Reading Metadata… DONE { take = 1ms }
We are going to remove 0 files, until 2024-12-27 13:20:30.4600.
Sure? (y/N)

尝试方法一:
[tidb@monitor ~]$ echo ‘yes’ | tiup br log truncate --until=${keep_full_backup_ts} --storage=‘/backup/tidb/log’

A new version of br is available: v8.3.0 → v8.5.0

To update this component:   tiup update br
To update all components:   tiup update --all

Starting component br: /home/tidb/.tiup/components/br/v8.3.0/br log truncate --until=454892409444106241 --storage=/backup/tidb/log
Detail BR log in /tmp/br.log.2024-12-26T16.08.03+0800
Reading Metadata… DONE { take = 1ms }
We are going to remove 0 files, until 2024-12-27 13:20:30.4600.
Clearing Data Files and Metadata :: DONE { take = 0s, kv-count = 0, kv-size = 0(0B) }

[tidb@monitor ~]$ echo ‘s’ | tiup br log truncate --until=${keep_full_backup_ts} --storage=‘/backup/tidb/log’

A new version of br is available: v8.3.0 → v8.5.0

To update this component:   tiup update br
To update all components:   tiup update --all

Starting component br: /home/tidb/.tiup/components/br/v8.3.0/br log truncate --until=454892409444106241 --storage=/backup/tidb/log
Detail BR log in /tmp/br.log.2024-12-26T16.08.10+0800
Reading Metadata… DONE { take = 1ms }
We are going to remove 0 files, until 2024-12-27 13:20:30.4600.
Clearing Data Files and Metadata :: DONE { take = 0s, kv-count = 0, kv-size = 0(0B) }

尝试方法二:
[tidb@monitor ~]$ yes|tiup br log truncate --until=${keep_full_backup_ts} --storage=‘/backup/tidb/log’

A new version of br is available: v8.3.0 → v8.5.0

To update this component:   tiup update br
To update all components:   tiup update --all

Starting component br: /home/tidb/.tiup/components/br/v8.3.0/br log truncate --until=454892409444106241 --storage=/backup/tidb/log
Detail BR log in /tmp/br.log.2024-12-26T16.10.25+0800
Reading Metadata… DONE { take = 1ms }
We are going to remove 0 files, until 2024-12-27 13:20:30.4600.
Clearing Data Files and Metadata :: DONE { take = 0s, kv-count = 0, kv-size = 0(0B) }

方法三:
[tidb@monitor ~]$ tiup br log truncate --until=${keep_full_backup_ts} --storage=‘/backup/tidb/log’<<EOF
yes
EOF

A new version of br is available: v8.3.0 → v8.5.0

To update this component:   tiup update br
To update all components:   tiup update --all

Starting component br: /home/tidb/.tiup/components/br/v8.3.0/br log truncate --until=454892409444106241 --storage=/backup/tidb/log
Detail BR log in /tmp/br.log.2024-12-26T16.16.25+0800
Reading Metadata… DONE { take = 0s }
We are going to remove 0 files, until 2024-12-27 13:20:30.4600.
Clearing Data Files and Metadata :: DONE { take = 0s, kv-count = 0, kv-size = 0(0B) }

[tidb@monitor ~]$ tiup br log truncate --until=${keep_full_backup_ts} --storage=‘/backup/tidb/log’<<EOF
hehe
EOF

A new version of br is available: v8.3.0 → v8.5.0

To update this component:   tiup update br
To update all components:   tiup update --all

Starting component br: /home/tidb/.tiup/components/br/v8.3.0/br log truncate --until=454892409444106241 --storage=/backup/tidb/log
Detail BR log in /tmp/br.log.2024-12-26T16.16.50+0800
Reading Metadata… DONE { take = 1ms }
We are going to remove 0 files, until 2024-12-27 13:20:30.4600.
Clearing Data Files and Metadata :: DONE { take = 0s, kv-count = 0, kv-size = 0(0B) }

不管输什么,结果都是一样,迷糊的我不知道到底哪个方法是正确的能自动输入确认信息。 :sweat_smile:

用expect吧。。。

1 个赞

tiup … -y 试试

shell yes 命令了解下。

或者 tiup xxx -y 一般够用了。

1 个赞

感谢,我就用tiup -y。

此话题已在最后回复的 7 天后被自动关闭。不再允许新回复。