Running a Block of Shell Script remotely using SSH

馋奶兔 提交于 2019-12-02 13:08:40

Just stream those commands into ssh stdin, like:

ssh remoteserver << EOF
command1
command2
command3
...
EOF

<< here means here-doc - a multiline quote.

This will do essentially what you're asking for:

while [[ $RecordCount -gt 0 ]]
do
  field1=$( sed -n ${RecordCount}p ${GUID_DLT_EXPR_FILE} | cut -d'|' -f1 )
  field2=$( sed -n ${RecordCount}p ${GUID_DLT_EXPR_FILE} | cut -d'|' -f2 )
  run_dt=$( sed -n ${RecordCount}p ${GUID_DLT_EXPR_FILE} | cut -d'|' -f3 )


  dir="/sas/ADH/exXd_${field1}"
  id_path="$dir/version_${field2}
  latest="$id_path/latest"
  archives="id_path/archives"

  ssh ${REMOTE_SERVER:?} "if [[ -d $id_path ]] &&
      ls -d $latest/* > /dev/null 2>& 1
    then
      mv -f $latest/* $archives
    else
      mkdir -p $latest $archives
    fi"

  update_recordcount

done

exit 0

BTW, you will need to provide your own versions of:

  • REMOTE_SERVER (variable)
  • update_recordcount (function) -- make sure it counts down to zero somehow.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!