anyone!! debug this small script..thanks in advance..

x="PermitRootLogin no"
cd /etc/ssh
y=`cat sshd_config |grep "PermitRootLogin"`
if [[ "$x" = "$y" ]]
then print "Sorry, Remote Root SSH login already disabled."
exit
else print "Welcome to Remote SSH Login disable script."
fi

output:

+ x=PermitRootLogin no
+ cd /etc/ssh
+ + cat sshd_config
y=PermitRootLogin no
+ [[ PermitRootLogin no = PermitRootLogin no ]]
+print " Welcome to Remote Root SSH Login disable script.
Welcome to Remote Root SSH Login disable script.

Here both $x=$y=PermitRootLogin no. Still it is executing as if $x!=$y ???
I worked around in another way,,but can someone tell me what is wrong with this damn script??
thanks in advance.

Hi,

take a close look at your variables.
$y begins with some spaces, $x doesn't.
Consequently:

if [[ "$x" = "$y" ]]

won't match, but

[[ "$x" = *"$y"* ]] && echo hit || echo miss

or

[[ "$x" =~ "$y" ]] && echo hit || echo miss

should.

HTH Chris

:> cat test
x=no
y=$(grep PermitRootLogin /etc/ssh/sshd_config | awk '{print $2}')
if [[ $y = $x ]]; then
   echo "already disabled"
else
   echo "welcome to disable script"
fi

:> ksh -kx /tmp/test
+ x=no
+ + awk {print $2}
+ grep PermitRootLogin /etc/ssh/sshd_config
y=yes
+ [[ yes = no ]]
+ echo welcome to disable script
welcome to disable script

What your code is comparing is

 no = RootPermitLogin