UNIX Shell Script

Hi I need a shell script
My requirement is something like adding entries to a file

cat fielname will have below 5 lines
ServerName:Test
Connection Attempt:yes
Connection retries:3
Max Sessions:5
Communication address:172.24.3.11

I have one such entry in a file.
Say i want to add more such entry with servername and Communication address going to change values and other variables remain same.

I want to device a script like i will grep for servername and if server name is present i will exit the script
if servername is not present i add a new entry
followed by communication address

my final file should be like this

ServerName:Test
Connection Attempt:yes
Connection retries:3
Max Sessions:5
Communication address:172.24.3.11

new entry added
ServerName:Test1
Connection Attempt:yes
Connection retries:3
Max Sessions:5
Communication address:172.24.3.12

What have you tried?

I tried using grep "Test" filename (where one single entry is available)

if [[ $? -eq 0 ]]; then
echo "Servername Test is present"
else 
echo "Add server entry"
fi

---------- Post updated at 03:52 PM ---------- Previous update was at 03:52 PM ----------

i am just spitballing, i need to add the ip address as well.

Why would you need the IP Address?
Doesn't DNS work?

But based on your original requirements, what you wrote is nearly correct:

if ! grep -q "^ServerName: ${NAME}" filename; then
    echo ${NAME}: add entry
fi

Using grep "Test" filename may result in false positives if the hostname matches a tag, such as "max".

It is a script for Connect Direct file transfer and i am trying to automate the update netmap entry so that i don't have to manually enter the server node and ip address.
The server and the communication address change everytime a new server is being added.

So - what exactly is the problem, now?

I am not able to complete the script,
I need to add the servername and the communication address.

---------- Post updated at 12:46 PM ---------- Previous update was at 12:45 PM ----------

say like the server entry is added on the 1st line of the contents
Communication address is on added on5,6 th line of the contents

Try

NAME=Test1
ADDR="172.122.42.21"
awk -F: -vNM="$NAME" -vCA="$ADDR" '

/ServerName/    {if ($2 == NM)  {EX++
                                 exit
                                }
                 $2 = NM
                }
/Comm.*ss/      {$2 = CA
                }

NR<=5           {LN[NR]=$0}

END             {if (!EX) for (i=1; i<=5; i++) print LN
                }
' OFS=":" file