Hi guys I am new in writing bash script.
I have a task to do. I have a file in which node name and ips are updated, I have to make each file of those nodes which are not in our required directory and those are in updated file and also editing their name.
I have to give input from bottom to upward means from last line to upward and my script will run from bottom to upward according to my need means those entries which are missing in my required directory.
I use if else condition and have to place for loop to do my task until it equals. My script is
!/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
but i am getting this error
line 43: syntax error near unexpected token fi'
line 43: fi '
Description of my script
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
any idea about syntax of for loop