0

I am using the below codes to change some file permissions:

encrypt=`sed -n '/:/,$p' $FILE_PATH_1 | cut -d':' -f2 | tr -d ' '`    
local listOfPasswordChangeWS=`$SMANAGER_SCRIPT status service PasswordChangeWS | cut -f 2 -d ":"`
for node in $listOfPasswordChangeWS ; do
  ssh -q $i "cp /opt/oss/NSN-mf_swp/smx/mf-conf/was-cred.properties /opt/oss/NSN-mf_swp/smx/mf-conf/was-cred.properties.original"
  ssh -q $i "sed -i '/Password/c\com.ibm.CORBA.loginPassword=ENC($encrypt)' /opt/oss/NSN-mf_swp/smx/mf-conf/was-cred.properties "
  **ssh -q $i "chown -c omc:sysop /opt/oss/NSN-mf_swp/smx/mf-conf/was-cred.properties ; chmod 640 /opt/oss/NSN-mf_swp/smx/mf-conf/was-cred.properties"**
 # INCR=$?
  INCR=$?
  if [ "INCR" == "0" ] ; then
  NewIncr++
  fi
done

I want to check the exit status but since it is in for loop i am not able to get value 0 or 1 instead it is returning value 255. My query is: 1. How can I check the exit status of chown -c command (Remember i am doing ssh) 2. How can I check whether my file permission has been changed to omc:sysop

  • check [this](http://stackoverflow.com/questions/5342402/can-i-get-the-exit-code-of-a-command-executed-in-a-subshell-via-ssh) or [this](http://stackoverflow.com/questions/15390978/shell-script-ssh-command-exit-status) out. – ArnonZ Mar 16 '15 at 05:24

1 Answers1

-1

Try this:

if ssh $HOST 'chown -c omc:sysop /opt/oss/NSN-mf_swp/smx/mf-conf/was-cred.properties ; chmod 640 /opt/oss/NSN-mf_swp/smx/mf-conf/was-cred.properties' < /dev/null
   if [ $? -eq 0 ]; then
     echo SUCCESS
   else
      echo FAIL
fi
Rupesh
  • 1,636
  • 13
  • 18
  • Your two `if` statements are redundant. The outer `if` will only execute the inner `if` when the ssh command exits successfully. So the inner if will only execute the SUCCESS block. – Kenster Mar 16 '15 at 12:22