Need help on bash script

Hi All,

I have created below script to check the svcs status.

  1. Check the svcs status
  2. If its in maintenace state output should be "Maintenace State"
  3. Else Print "Running "

Script:

#!/bin/bash
S=$(/usr/bin/svcs -H -o STATE  sasm)
if [$S='maintenance'];
then
echo "SASM is in maintenance state" 
else
echo "SASM is running fine"
fi

error:

[root@7cta-446-oicl ] $: ./b.sh
./b.sh: line 3: [maintenance=maintenance]: command not found

Use code tags...

try this...

#!/bin/bash
S=$(/usr/bin/svcs -H -o STATE  sasm)
if [[ "$S" == "maintenance" ]]
then
echo "SASM is in maintenance state" 
else
echo "SASM is running fine"
fi

wooow.. its workging.. thanks a lot...

The problem in your first post was missing spaces

 if [$S='maintenance'];

should be

 if [ "$S" = 'maintenance' ];

Also adding quotes surrounding $S, if $S is empty it will be an error otherwise.
If you use [[ ... ]] like @panu suggested you don't need surrounding quotes.