使用SSH远程运行Shell脚本块 [英] Running a Block of Shell Script remotely using SSH

查看:93
本文介绍了使用SSH远程运行Shell脚本块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Shell脚本在其他服务器上执行命令块

I am try to execute a block of commands on a different server using a shell script

有人可以帮我吗

while [ $RecordCount -gt 0 ]
do
  expXXXXX=`sed -n ${RecordCount}p ${GUID_DLT_EXPR_FILE} | cut -d "|" -f1`
  exprXXXXXn_id=`sed -n ${RecordCount}p ${GUID_DLT_EXPR_FILE} | cut -d'|' -f2`
  run_dt=`sed -n ${RecordCount}p ${GUID_DLT_EXPR_FILE} | cut -d'|' -f3`

  #START OF THE BLOCK - IN SERVER 2   

  if [ -d "/sas/ADH/exXd_$expXXXXX" ]; then
    if [ -d "/sas/ADH/exXd_$expXXXXX/version_$exprXXXXXn_id" ]; then
      mv -f /sas/ADH/exXd_$expXXXXX/version_$exprXXXXXn_id/latest/* \
        /sas/ADH/exXd_$expXXXXX/version_$exprXXXXXn_id/archives
    else    
      mkdir /sas/ADH/exXd_$expXXXXX/version_$exprXXXXXn_id
      mkdir /sas/ADH/exXd_$expXXXXX/version_$exprXXXXXn_id/latest
      mkdir /sas/ADH/exXd_$expXXXXX/version_$exprXXXXXn_id/archives
    fi
  else 
    mkdir /sas/ADH/exXd_$expXXXXX
    mkdir /sas/ADH/exXd_$expXXXXX/version_$exprXXXXXn_id
    mkdir /sas/ADH/exXd_$expXXXXX/version_$exprXXXXXn_id/latest
    mkdir /sas/ADH/exXd_$expXXXXX/version_$exprXXXXXn_id/archives
  fi

  #END OF THE BLOCK - IN SERVER 2

done

exit 0

推荐答案

只需将这些命令流式传输到ssh stdin中,例如:

Just stream those commands into ssh stdin, like:

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

<<在这里表示此处文档-多行引号

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

这篇关于使用SSH远程运行Shell脚本块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆