-1

我有一个 shell 脚本来做以下事情

  1. sudo 作为用户 (johnsmith) 并执行一些操作
  2. 从该用户退出并检查 url 状态
  3. 如果 status 不等于 1 ,则 ssh 到另一台服务器并执行脚本。

但是当我运行它时,里面的行'ENDBASH'根本没有被执行。

     #!/bin/ksh
     echo "Outside ENDBASH ${@##*/}"

    sudo -u johnssmith bash <<'ENDBASH'  

    echo "Inside ENDBASH ${@##*/}"

    #Obtaining the new version file
    for file in "${@##*/}"
     do
     if echo "$file" | grep -E "abc_cde_efg"; then
         echo "Version found: $file"
    else
           echo "Version not found"
    fi
    done        
    exit
ENDBASH

urlArray=('http://server:port/servicename1/services/servicename1?wsdl' 'http://server:port/servicename2/services/servicename2?wsdl')

status=0
    for url in "${urlArray[@]}"
     do
       result=`curl -s $url`

        if (echo $result | grep '<?xml' >/dev/null 2>&1); then
           service=$(echo $url | cut -d"/" -f4)
           echo "$service is Running"
      else
           service=$(echo $url | cut -d"/" -f4)
          echo "$service is not Running"
         status=1
        fi
     done    
if [ $status != 1 ] ; then
 ssh -t username@hostname /home/dev_was/test1.sh 
fi
4

1 回答 1

0

您需要将脚本接收到的参数显式传递给内部脚本:

sudo -u johnssmith bash -s "$@" <<'ENDBASH' 
于 2013-06-17T16:39:16.353 回答