if statement to check $HOSTNAME in shell script

You're missing a space after the opening bracket. It's also good "not to parse" the variable content using double quotes:

if [ "$HOSTNAME" = "foo" ]; then 
    ...

The POSIX and portable way to compare strings in the shell is

if [ "$HOSTNAME" = foo ]; then
    printf '%s\n' "on the right host"
else
    printf '%s\n' "uh-oh, not on foo"
fi

A case statement may be more flexible, though:

case $HOSTNAME in
  (foo) echo "Woohoo, we're on foo!";;
  (bar) echo "Oops, bar? Are you kidding?";;
  (*)   echo "How did I get in the middle of nowhere?";;
esac