【问题标题】:How to change file permission while doing ssh in shell如何在 shell 中执行 ssh 时更改文件权限
【发布时间】:2015-03-16 13:32:55
【问题描述】:

我正在使用以下代码来更改一些文件权限:

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

我想检查退出状态,但由于它在 for 循环中,我无法获得值 0 或 1,而是返回值 255。我的查询是: 1. 如何查看 chown -c 命令的退出状态(记住我在做 ssh) 2.如何查看我的文件权限是否已更改为omc:sysop

【问题讨论】:

标签: linux bash shell ssh


【解决方案1】:

试试这个:

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

【讨论】:

  • 您的两个if 语句是多余的。外部if 只会在ssh 命令成功退出时执行内部if。所以内部 if 只会执行 SUCCESS 块。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-10-23
  • 2010-12-09
  • 2015-04-14
  • 1970-01-01
  • 2019-10-03
  • 2013-10-24
  • 2013-12-30
相关资源
最近更新 更多