ifeatu
asked on
Pattern matching if statement in shell script
I want my script to search the variable "$env" and find the word "prod" (without the quotes)
and if it finds it I want it to say that its a production server
for some reason my pattern matching doesnt seem to work
and if it finds it I want it to say that its a production server
for some reason my pattern matching doesnt seem to work
#!/bin/sh
# unixinf
# gather information for unix system
#
env=`grep hcsEnvironment /etc/hcs.info`
mname=`uname -n`
supteam=`grep hcsTEAM /etc/hcs.info`
unixver=`uname`
#
if [ "$env" == *prod* ]; then
echo "This is a production Server!"
fi
echo "Machine Name" > /home/tsv0g0/tmp/chkout
uname -a >> /home/tsv0g0/tmp/chkout
echo " " >> /home/tsv0g0/tmp/chkout
echo "The support team for $mname: $supteam" >> /home/tsv0g0/tmp/chkout
echo "The status of $mname: $env" >> /home/tsv0g0/tmp/chkout
echo " " >> /home/tsv0g0/tmp/chkout
echo "Uptime" >> /home/tsv0g0/tmp/chkout
uptime >> /home/tsv0g0/tmp/chkout
echo " " >> /home/tsv0g0/tmp/chkout
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
w
A generic solution that will work on all Unix/Linux flavours is
if echo "$env" | grep prod >/dev/null
then
echo "This is a production server"
fi