用shell 写段批量显示节点的脚本,节点在txt中。最后把输出保存到新txt中
时间: 2023-04-07 07:03:40 浏览: 44
可以使用以下的 shell 脚本来实现:
```
#!/bin/bash
# 读取节点列表
while read node; do
# 显示节点信息
echo "Node: $node"
done < nodes.txt > output.txt
```
其中,`nodes.txt` 是存储节点列表的文本文件,每行一个节点名称。脚本会逐行读取节点名称,然后在屏幕上显示节点信息,并将输出保存到 `output.txt` 文件中。
相关问题
用shell 写段批量重启节点的脚本,节点在txt中。最后把输出保存到新txt中
可以使用以下脚本实现:
#!/bin/bash
while read node; do
echo "restarting $node"
ssh $node "sudo reboot"
done < nodes.txt > output.txt
这个脚本会读取 nodes.txt 文件中的节点列表,然后逐个重启每个节点,并将输出保存到 output.txt 文件中。
用shell 写段批量重启节点的脚本,节点在txt中
我可以回答这个问题。以下是一个简单的批量重启节点的脚本:
#!/bin/bash
while read node; do
ssh $node "sudo reboot"
done < nodes.txt
其中,nodes.txt 是包含节点名称或 IP 地址的文本文件。脚本将逐行读取该文件中的节点名称或 IP 地址,并使用 ssh 命令连接到每个节点并执行 sudo reboot 命令以重启节点。