【发布时间】:2014-05-06 07:30:50
【问题描述】:
首先我的脚本很弱,所以请耐心等待这个算法只是为了解释我的问题:
第 1 阶段:从 Server-1 获取所有信息,并将其保存在文本文件中。
第 2 阶段:将文本文件复制到 Server-2 并重新运行脚本以创建与 Server-1 中存在的类似信息
第一阶段:
file1.txt:
第1行
第2行
第3行
第4行
如果我在 file1.txt 的 row1 上运行 command1,它会给我如下输出:
./command1 row1 > output
猫输出
冬季:1456
夏季:5467
春天:2314
秋季:3443
类似地,所有其他带有 command1 的行将有 4 个带有不同季节代码的其他输出。 4个输出是为了简单。我拥有的 - 处理的每个命令输出中都有大约 40 个输出。
现在我需要知道如何将这 16 个输出放在 output.txt 中,以便我可以在另一台服务器中重新创建相同的信息?
--
@mofoe 回复后更新:
嘿,首先谢谢你。我认为这是朝着正确的方向发展。 所以我认为这让我进入了组织输出的最后一步,以便将这些数据输入回另一台服务器。
考虑这个带有静态输出的 ping 命令,并忽略任何动态或变化的值,想想看,它的一些命令输出将用于进入位于其他地方的另一台服务器。由于将运行许多不同的命令以进入系统,因此不能仅通过粘贴整个文本文件或整行来完成类似的操作。只有某些部分是重要和需要的。再次,我真的很感谢你回答一个蹩脚的问题。谢谢。
这就是我们现在的立场。我是用Ping命令给你解释的,其实和ping没有任何关系。将其视为其他命令的标准静态输出。
[root@host-11 test]# cat file1.txt
#only 2 hosts are typed in here, originally there are 500+
host-11
host-12
[root@host-11 test]# cat script
#!/bin/sh
while read line; do
/bin/ping -c 4 $line >> output.txt
done < file1.txt
[root@host-11 test]# cat output.txt
PING host-11 (x.x.x.x) 56(84) bytes of data.
64 bytes from host-11 (x.x.x.x): icmp_seq=1 ttl=64 time=0.023 ms
64 bytes from host-11 (x.x.x.x): icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from host-11 (x.x.x.x): icmp_seq=3 ttl=64 time=0.038 ms
64 bytes from host-11 (x.x.x.x): icmp_seq=4 ttl=64 time=0.034 ms
--- host-11 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.023/0.032/0.038/0.009 ms
PING host-12 (y.y.y.y) 56(84) bytes of data.
64 bytes from host-12 (y.y.y.y): icmp_seq=1 ttl=64 time=0.228 ms
64 bytes from host-12 (y.y.y.y): icmp_seq=2 ttl=64 time=0.267 ms
64 bytes from host-12 (y.y.y.y): icmp_seq=3 ttl=64 time=0.264 ms
64 bytes from host-12 (y.y.y.y): icmp_seq=4 ttl=64 time=0.246 ms
--- host-12 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.228/0.251/0.267/0.019 ms
所以现在,我需要有条理的文本文件,如下所示:
猫输出.txt
host-name IP icmp_seq1 icmp_seq2 rtt
host-11: (x.x.x.x) time=0.023 time=0.036 0.023/0.032/0.038/0.009
host-12: (y.y.y.y) time=0.228 time=0.267 0.228/0.251/0.267/0.019
** all other hosts that might have been included in the file1.txt
所以一旦我有了这个,我就必须运行 4 个不同的命令才能在另一台服务器中输入这个。我希望它现在更有意义?
【问题讨论】:
标签: arrays linux bash ksh redhat