我在脚本中使用下面的代码,它应该匹配hosts.test中的"title随机Linux服务器“,并在2行匹配字符串之后将t3文件的文本插入到hosts.test中。但它带来了一些错误。
sed -i.bak '/^title AHS - zarriot CBTS random Linux Servers$/ {N;N; r t3}' hosts.test
有人能帮我吗?
我正在尝试对某些节点使用chef搜索:
hosts = search(:node, 'chef_environment:STG AND role:elasticsearch')
Chef::Log.warn("Hosts are #{hosts}")
hosts.each do |node|
Chef::Log.warn("hostname is: #{node['name']} and has the following tags #{node["tags"]}")
end
第一个Chef::Log.warn
如何在一个命令行中运行对应的sed命令?
sed -i s'/12.1.0.11/#12.1.0.11/g' /etc/hosts
sed -i s'/12.1.0.12/#12.1.0.12/g' /etc/hosts
sed -i s'/12.1.0.21/#12.1.0.21/g' /etc/hosts
sed -i s'/12.1.0.22/#12.1.0.22/g' /etc/hosts
我的目标是通过ssh更新目标主机文件。
我不想跑4次!
示例
ssh linux1 sed -i s'/12
我在.sh文件中定义了一个数组,如下所示:
hosts=(NODE IPS)
hosts[0]="1.110,Node-01"
hosts[1]="1.111,Node-02"
hosts[2]="1.112,Node-03"
hosts[3]="1.113,Node-04"
hosts[4]="1.114,Node-05"
hosts[5]="1.115,Node-06"
如何循环数组,但根据逗号拆分每个索引,并将值存储在变量中,如下所示:
for index in ${!hosts[*]}
do
这个代码几乎是完美的,但是第二个编号并不像预期的那样工作。
user@linux:~$ cat ip.txt
10.1.1.1
10.2.2.2
10.3.3.3
user@linux:~$
script.py
from netmiko import Netmiko
with open('ip.txt') as f:
print('List of Hosts')
print('-' * 13)
for x,y in enumerate(f.read().split(), 1):
print(f'
我的情况是这样的:
我有一个基于windows的服务器程序和一个基于linux的客户端。
我为linux客户端进行了许多测试,这些客户端运行并需要在本地linux机器上运行。
我需要从windows服务器机器运行一些代码,这将发送一些消息给linux客户端。然后,将在linux客户端机器上执行测试,以验证这些消息的效果。
因此,典型的测试用例看起来如下所示,运行在windows主机上:
test_example_message(self):
# has to be executed locally on windows server
send_message
将码头输出保存到宿主
中
docker run centos cat /etc/hosts > asdf
asdf保存在我的主机linux中。
将码头输出保存到容器
docker run centos sh -c 'cat /etc/hosts > /tmp/asdf '
docker run centos cat /tmp/asdf
cat: /tmp/asdf: No such file or directory
这不管用,我怎么做呢?
容器中的
<:
docker run centos sh -c 'cat < /etc/hosts'
将Docker输出保存到主机
docker run centos cat /etc/hosts > asdf
"asdf“保存在我的主机Linux中。
将码头输出保存到容器中
docker run centos sh -c 'cat /etc/hosts > /tmp/asdf '
docker run centos cat /tmp/asdf
cat: /tmp/asdf: No such file or directory
它不工作,我怎么能猫新的文件?
在容器中使用"<“
docker run centos sh -c 'cat