Reading a file for specific words

Hi

I have a script where the user calls it with arguments like so:

./import.sh -s DNSNAME -d DBNAME

I want to check that the database entered is valid by going through a passwd.ds file and checking if the database exists there.
If it doesn't, the I need to send a message to my log file.

Thanks

Try this:

grep $DBNAME password.ds
if [ $? -ne 0 ]
then
   exit
fi

Hi

I've tried this:

grep $dbname $passwddir
if [$? -ne 0]
then 
dsxlog $reverb --info --module="$module" "$dbname - dbname does not exist" 
exit
fi

It seems to skip the if statement.

Is there any other options to try?

Thanks
[/SIZE][/FONT][/SIZE][/FONT]

You can put the grep right in the statement:

if ! grep -q "${dbname}" "${passwddir}"
then
        dsxlog "${reverb}" --info --module="$module" "$dbname - dbname does not exist" 
        exit
fi

if it continues to not work, check to make sure all the variables are what you think they are...

Assuming the code in post 3 is exactly as you have it on disk, a space is required after the [ and before the ], in line 2.