【发布时间】:2015-03-20 00:27:47
【问题描述】:
大家好,我是编写 bash 脚本的新手。
我有一个任务要做。我有一个文件,其中更新了节点名称和 ips,我必须制作不在我们所需目录中的那些节点的每个文件,这些节点在更新的文件中并编辑它们的名称。
我必须从下到上提供输入,即从最后一行到上,我的脚本将根据我的需要从下到上运行,这意味着我所需目录中缺少的那些条目。
我使用 if else 条件并且必须放置 for 循环来完成我的任务,直到它等于。我的脚本是
!/bin/bash
set -x
giosdir=$(find /usr/local/example-dir -maxdepth 1 -type f | wc -l)
lbdir=$(more /root/scripts/servers/new/example.txt |wc -l)
count=$(($lbdir-$giosdir))
lait2=1
l2=$(awk '{print $3}' < /root/scripts/servers/new/example.txt | tail -$lait2)
lait=1
newip=$(awk '{print $1}' < /root/scripts/servers/new/example.txt | tail -$lait)
if [ $nagiosdir -eq $lbdir ] ; then
echo " Nothing to do "
else
if [ $giosdir -lt $lbdir ] ; then
for((i=0;i<count;i++));do
{
cd /usr/local/
cp example-Node-2.txt $l2.txt
sed -i 's/10.10.0.1/'$newip'/' $l2.txt
sed -i 's/examole-Node-2.txt/'$l2'/' $l2.txt
echo " Node is added successfull"
lait2++;
lait++;
}
fi
fi
但我收到此错误
line 43: syntax error near unexpected token fi'
line 43: fi '
我的脚本描述
1 first line is taking input from a directory that how many number
of files are there.
2 This line is taking input from a file that how many lines are
there
3 subtracting the numbers and the value would be an integer
4 declaring variable valu which is use in next line
5 this line taking input from a file and cut the 3rd column in which
nodes name are save
6 also a variable
7 taking an ip as an input from a file
8 if condition
关于for循环语法的任何想法
【问题讨论】: