title: Why it is exit when ssh remote executed script in linux shell
body: <p>In my project, i need to find the user processed on node.</p>
  <p>I have a file: jodIdUser. The content in this file has two columns, like:</p>
  <pre><code>395163 chem-yupy
  395164 chem-yupy
  395165 phy-xiel
  395710 mae-chent
  </code></pre>
  <p>Now i have a script appRecord.sh, and i have a whle loop in it.
  The while method code is like:</p>
  <pre><code>cat $workDir/jobIdUser | while read LINE
  do
    jobUser=`echo $LINE | awk '{print $2}'`
    jobId=`echo $LINE | awk '{print $1}'`
  
    jobOnNodes=`/usr/bin/jobToNode $jobId | xargs`
    echo $timeStr&quot; &quot;$jobId&quot; &quot;$jobUser&quot; &quot;$jobOnNodes  &gt;&gt; $workDir/tmpRecFile
  
    #20200702, it is needed to find out user process on nodes at this time here
     designatedNode=`echo $jobOnNodes | awk '{print $NF}'`
     echo $jobOnNodes
     echo $designatedNode
  
     ssh $designatedNode sh $workDir/nodeProInfo.sh       ##Here code will exit while loop
     echo $timeStr&quot; &quot;$jobId&quot; &quot;$jobUser&quot; &quot;$jobOnNodes &gt;&gt; $workDir/$recordFile
   done
  </code></pre>
  <p>The code of nodeProInfo.sh is like:</p>
  <pre><code>#!/bin/bash
  source /etc/profile
  workDir=/work/ccse-xiezy/appRecord
  
  hostName=`hostname`
  jobInfo=`ps axo user:15,comm | grep -Ev &quot;libstor|UID|ganglia|root|gdm|postfix|USER|rpc|polkitd|dbus|chrony|libstoragemgmt|para-test|ssh|ccse-x|lsf|lsbatch&quot; | tail -n 1`
  
  echo $hostName&quot; &quot;$jobInfo &gt;&gt; $workDir/proRes
  </code></pre>
  <p>Now I run the script sh appRecord.sh, it is wrong. It will exit when the first loop in while</p>
  <pre><code>[cc@login04 appRecord]$ sh appRecord.sh 
   r03n56 r04n09 r04n15
   r04n15
  [cc@login04 appRecord]$
  </code></pre>
  <p>I don't know why it will exit when remote ssh node method, who can help me?</p>
  <p>UPDATE:</p>
  <p>I have another script which runns ok. the jobIdUser has content like:</p>
  <pre><code>   r01n23  xxx-ser
     r92n12  yyn-ser
  </code></pre>
  <p>and the while loop is:</p>
  <pre><code>cat $workDir/jobIdUser | while read LINE
  do
       .............
       ssh $NODE pkill -u -9 $USER
       .............
  done
  </code></pre>