Bash for连续循环2个文件,并将参数传递给其他脚本
我有两个文件,一个是Bash for连续循环2个文件,并将参数传递给其他脚本,bash,shell,Bash,Shell,我有两个文件,一个是hostnames.txt,另一个是commands.txt: hostnames.txt: switch1.txt switch2.txt switch3.txt show inter gi0/1 show inter gi0/0/1 show inter Eth1/1 commands.txt: switch1.txt switch2.txt switch3.txt show inter gi0/1 show inter gi0/0/1 show inter Eth
hostnames.txt
,另一个是commands.txt
:
hostnames.txt
:
switch1.txt
switch2.txt
switch3.txt
show inter gi0/1
show inter gi0/0/1
show inter Eth1/1
commands.txt
:
switch1.txt
switch2.txt
switch3.txt
show inter gi0/1
show inter gi0/0/1
show inter Eth1/1
我想用show inter-gi0/1
(第一个命令)执行switch1
(第一个开关),然后选择switch2
并用show inter-gi0/0/1
执行,依此类推,直到文件结束
我使用的是一个TCL脚本,通过文本文件向其传递带有主机名和命令的参数
for in `/bin/cat hostname.list`;
do
echo $n > oneswitch.txt
for in `/bin/cat interfinal.list`;
do
echo $m > onecommand.txt
for switch in `/bin/cat oneswitch.txt
tclscript -u username -p password -t $switch -r onecommand.txt .
我无法实现它,我可以如何使用和使用哪些可能的循环,我可以使用什么登录来实现它
使用上面的一个命令所发生的事情是,我只能使用最后一个开关和最后一个命令来执行
请帮忙
谢谢使用
粘贴
->在bash提示符下尝试:粘贴-d:“hostname.list interfinal.list
因此:
你可以做:
#!/usr/bin/env bash
for i in {1..3}; do
eval $(paste -d' ' <(sed -n ${i}p commands.txt) <(sed -n ${i}p hostnames.txt))
done