There should be no need to use grep for this purpose. Just use your shell's built-in text string comparsion tests.
To start with, you haven't mentioned what scripting environment you're talking about. Some shells provide a built in $HOSTNAME envrionment variable for you already. But if not, capture the hostname command into to one.
Next, there are several different ways to go about testing the string, but I pesonally recommend a
case statement, which is fully portable and usually the most efficient.
Code:
case $host in #or $HOSTNAME, if available
s001ap12.*|S001AP12.*)
echo "this is S001ap12"
RC=0
;;
esac
Another benefit is that you can add as many entries as you need, if you have to test multiple hosts.
If you're using
bash, you can more easily make it case-insensitive by converting the input with the appropriate
parameter substitution.
Code:
case ${host,,} in #or $HOSTNAME, if available
s001ap12.*)
echo "this is S001ap12"
RC=0
;;
esac
You can also use
bash's
[[..]] expanded test brackets, which support both
globbing and regular expression matches.
http://mywiki.wooledge.org/BashFAQ/031