Question in bash script.

Hi All,
I need an assistance with the issue below.
I wrote big script in "bash" that automatically install an LDAP on Clients.
I'd be happy to know in order to avoid duplication of entries in files,
How i can define into the script, if the specific expressions already exist in the file, do not add them again.
For example i take the following section from the script :

echo "admin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo "%linuxadmin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

How i define in the script , only if the value are already exists in the file , do not add it again.
i have the same thing with sections that write expressions to more files.
The thing is that i sometimes i need to run the script more than once on the same server,and as a result of that it created duplicate values in multiple files.
Thank you guys,

Aviel.

If you just want to avoid duplicating the string you would add with your script...

egrep "$value" $file || echo "$value" >> $file

Skrynesaver,
can you be more specific,

At the section :

#Add permission to sysadmin
echo "admin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo "%linuxadmin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

Where i should put the expressions before or after this section ,
And how do you write the expression you gave me that would be suitable for the pare here,

Thanks ,

Aviel.

It's just checking the return value of grep for the existence of the record you wish to add in the file...

value='admin ALL=(ALL) NOPASSWD: ALL'
file=/etc/sudoers
grep "$value" $file || echo "$value" >> $file
value="%linuxadmin ALL=(ALL) NOPASSWD: ALL"
grep "$value" $file || echo "$value" >> $file

I Add it to the script, but it didnt work.
The Duplicate value still getting added to /etc/sudoers

Did you replace the 2 lines echoing the value to the file without checks?

Added to the script :

value='admin ALL=(ALL) NOPASSWD: ALL'
file=/etc/sudoers
grep "$value" $file || echo "$value" >> $file
value="%linuxadmin ALL=(ALL) NOPASSWD: ALL"
grep "$value" $file || echo "$value" >> $file
deleted from script : 
#Provide to system administrators accounts root privileges
echo "admin        ALL=(ALL)       NOPASSWD: ALL"   >> /etc/sudoers echo "%linuxadmin  ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers

strange, which flavour of grep are you using...the brackets may be being interpreted as grouping parenthesis rather than strings by grep... in which case you would have to escape them.