shell脚本无法正常工作

时间:2013-06-17 15:32:09

标签: ssh ksh remote-access

我有一个shell脚本来执行以下操作

  1. sudo作为用户(johnsmith)并执行一些事情
  2. 退出该用户并检查网址状态
  3. 如果status不等于1,则ssh到另一台服务器并执行a 脚本。
  4. 但是当我运行它时,'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
    

1 个答案:

答案 0 :(得分:0)

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

sudo -u johnssmith bash -s "$@" <<'ENDBASH'