带有引用文本文件中 id 的变量的 linux 脚本或 mass citrix vm snapshot delete

标签 linux shell citrix

我有一个命令(citrix xenserver cli delete snapshot 命令——如果重要的话)我必须重复多次:

xe snapshot-uninstall snapshot-uuid=[snapshot-uuid]

我想使用 [snapshot-uuid] 的变量编写此脚本,以便我可以重复文本文件中的所有行,看起来像这样(每行都是一个唯一的 uuid,没有空格):

dd56e7d2-00b0-4ddd-b3bf-368e3de059f9
ba201e7e-c180-4e00-8134-2ea128c9a14e
32128f38-b1b5-40e7-848c-dbdf5ae255ed
b53145ec-3748-475d-8add-008665533f72
173cb6c4-04da-43bc-abce-f2c97f76d3d2
3829f365-e619-47a0-93cd-d5aca37c28dd
6eb7aff9-70f9-4a77-96b0-044dfb0ce96e
ca7478c6-eae1-4090-aed5-c348b172d12a
439e247d-cf6a-4f09-a4d7-8dc719c317ca
b595d2e8-e2c4-4d0e-9b07-cccf1108904b
1da57650-dc16-48e2-bf5f-e2b8b96dba03
f2718a31-baa8-4c74-b170-5933e71da8c4
b2263c61-175e-43fa-b941-52ec2379a835
d0d6ede9-0589-4908-884f-900fef1d1c92
65e54f20-8c33-4f67-a394-36676add54ac
6d0f388c-5a78-4962-b1b2-55117b18a4c9

另一个复杂的问题是,对于每个命令,都会给出“您确定...键入‘是’以继续”。

更新:我最初发布这个问题是因为我在 Citrix 的 Xenserver CLI 论坛上提出的问题被忽略了。后来我确实在 Citrix 论坛上得到了回复 here ,其中包含一个比我尝试执行的命令更有效的命令。如果有人需要删除所有快照,请使用以下命令:

for i in `xe snapshot-list --minimal | sed -e 's/,/\ /g'` ; do xe snapshot-uninstall force=true uuid=$i ; done

最佳答案

您可以创建一个 shell 脚本来遍历每一行:

#!/bin/bash

while read UUID; do
    yes | xe snapshot-uninstall snapshot-uuid="$UUID"
done < uuids.txt

或者,如果您是一名优秀的打字员,您可以直接在您的 shell 中输入 while 循环的所有三行。

您可以通过管道输出 yes 来自动回答任何提示。 yes 将重复打印您选择的字符串(默认为“y”):

Name

yes - output a string repeatedly until killed

Synopsis

yes [STRING]...

Description

Repeatedly output a line with all specified STRING(s), or ‘y’.

关于带有引用文本文件中 id 的变量的 linux 脚本或 mass citrix vm snapshot delete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4227222/

相关文章:

linux - 是否可以在没有任何编译器的情况下使用 cmake

c++ - ubuntu 18.10 上的 std::filesystem 链接错误

Linux:如何检查 guest 虚拟机中的所有核心是否都在使用

bash - 来自Alpine的Docker phpunit:3.7输入shell CLI sh或bash

.net - 通过 .NET 中的 Citrix session 获取本地计算机名称

linux - 为什么 Gradle 在 :linkDebugTestLinux in my Kotlin multiplatform project? 上失败

bash - 使用 expect(1) 登录 SSH。如何退出 expect 并留在 SSH 中?

shell - 无法创建以日期命名的远程目录

automation - Citrix 中的 UI 自动化

vb6 - 受 MsgBox 影响的 VB 6 数据访问