<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: while loop exits after call to ssh in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617941#M104628</link>
    <description>I've checked the return code of the sudo and it is zero.&lt;BR /&gt;&lt;BR /&gt;I also tried the cat `echo ${ORATAB}` and that didn't make a difference.</description>
    <pubDate>Fri, 02 Sep 2005 15:18:47 GMT</pubDate>
    <dc:creator>Kevin Nikiforuk</dc:creator>
    <dc:date>2005-09-02T15:18:47Z</dc:date>
    <item>
      <title>while loop exits after call to ssh</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617938#M104625</link>
      <description>The DBA team I work with has a shell script for starting and stopping their databases that uses sudo (1.6.6) to change to another account, then ssh (A.03.81.002) to a remote server to work with the Oracle Application Stack. Here is a code snippet: &lt;BR /&gt;&lt;BR /&gt;==============================================&lt;BR /&gt;ORATAB=/etc/oratab &lt;BR /&gt;&lt;BR /&gt;trap 'exit' 1 2 3 &lt;BR /&gt;case ${ORACLE_TRACE} in &lt;BR /&gt;  T) set -x ;; &lt;BR /&gt;esac &lt;BR /&gt;&lt;BR /&gt;# Set path if path not set (if called from /etc/rc) &lt;BR /&gt;case ${PATH} in &lt;BR /&gt;  "") PATH=/bin:/usr/bin:/etc &lt;BR /&gt;    export PATH ;; &lt;BR /&gt;esac &lt;BR /&gt;&lt;BR /&gt;cat ${ORATAB} | while read LINE &lt;BR /&gt;do &lt;BR /&gt;  case ${LINE} in &lt;BR /&gt;    \#*) #comment-line in oratab &lt;BR /&gt;      ;; &lt;BR /&gt;    *) &lt;BR /&gt;      # Proceed only if third field is 'Y'. &lt;BR /&gt;      if [ "`echo $LINE | awk -F: '{print $3}' -`" = "Y" ] ; then &lt;BR /&gt;        ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` &lt;BR /&gt;        if [ "${ORACLE_SID}" != '*' ] ; then &lt;BR /&gt;          APPSUSER=`grep $ORACLE_SID /home/oraoper/bin/apps.pwd | awk '{print $5} '` &lt;BR /&gt;          echo $ORACLE_SID " " $APPSUSER &lt;BR /&gt;          if [[ -n $APPSUSER ]] &lt;BR /&gt;          then &lt;BR /&gt;            typeset -u APPSNODE=`grep $ORACLE_SID /home/oraoper/bin/apps.pwd | awk '{print $6} '` &lt;BR /&gt;            typeset -u NODE=`uname -n` &lt;BR /&gt;            /opt/sudo/bin/sudo -u $APPSUSER ssh $APPSUSER@$APPSNODE ls -l &lt;BR /&gt;          fi &lt;BR /&gt;       fi &lt;BR /&gt;    fi &lt;BR /&gt;    ;; &lt;BR /&gt;  esac &lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;==============================================&lt;BR /&gt;&lt;BR /&gt;The first time it hits an SID that requires the call to sudo and ssh, it completes the sudo and ssh, but when it returns to the top of the while loop, it exits, even though there are still lines to process. &lt;BR /&gt;&lt;BR /&gt;Any suggestions?</description>
      <pubDate>Fri, 02 Sep 2005 14:11:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617938#M104625</guid>
      <dc:creator>Kevin Nikiforuk</dc:creator>
      <dc:date>2005-09-02T14:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: while loop exits after call to ssh</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617939#M104626</link>
      <description>ssh exits with the exit status of the command that is run. Is it possible that if all files are not listed with the ls -l that the exit status of ls is &amp;gt;0 and even though ssh exits, it is passing the non-zero exit status to the script. &lt;BR /&gt;&lt;BR /&gt;Make sure of the permissions of the directory and files you are listing.&lt;BR /&gt;&lt;BR /&gt;man ssh</description>
      <pubDate>Fri, 02 Sep 2005 14:20:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617939#M104626</guid>
      <dc:creator>John Dvorchak</dc:creator>
      <dc:date>2005-09-02T14:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: while loop exits after call to ssh</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617940#M104627</link>
      <description>Not sure about this but still can you check if this works for you:&lt;BR /&gt;Instead of "cat ${ORATAB} | while read LINE"&lt;BR /&gt;use&lt;BR /&gt;"cat `echo $ORATAB` | while read LINE"&lt;BR /&gt;&lt;BR /&gt;i have used back quotes for echo oratab.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Sep 2005 14:22:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617940#M104627</guid>
      <dc:creator>Bharat Katkar</dc:creator>
      <dc:date>2005-09-02T14:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: while loop exits after call to ssh</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617941#M104628</link>
      <description>I've checked the return code of the sudo and it is zero.&lt;BR /&gt;&lt;BR /&gt;I also tried the cat `echo ${ORATAB}` and that didn't make a difference.</description>
      <pubDate>Fri, 02 Sep 2005 15:18:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617941#M104628</guid>
      <dc:creator>Kevin Nikiforuk</dc:creator>
      <dc:date>2005-09-02T15:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: while loop exits after call to ssh</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617942#M104629</link>
      <description>IT happens because you have a pipe there and ssh (and there some more commands) that break this pipe and the loop ends. It's a known issue.&lt;BR /&gt;&lt;BR /&gt;You must use "-f" or "-n" option of ssh:&lt;BR /&gt;&lt;BR /&gt;-f      Requests ssh to go to background just before command execution.&lt;BR /&gt;      This is useful if ssh is going to ask for passwords or&lt;BR /&gt;      passphrases, but the user wants it in the background.  This&lt;BR /&gt;      implies -n.  The recommended way to start X11 programs at a&lt;BR /&gt;      remote site is with something like ssh -f host xterm.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;-n      Redirects stdin from /dev/null (actually, prevents reading from&lt;BR /&gt;      stdin).  This must be used when ssh is run in the background.  A&lt;BR /&gt;      common trick is to use this to run X11 programs on a remote&lt;BR /&gt;      machine.  For example, ssh -n shadows.cs.hut.fi emacs &amp;amp; will&lt;BR /&gt;      start an emacs on shadows.cs.hut.fi, and the X11 connection will&lt;BR /&gt;      be automatically forwarded over an encrypted channel.  The ssh&lt;BR /&gt;      program will be put in the background.  (This does not work if&lt;BR /&gt;      ssh needs to ask for a password or passphrase; see also the -f&lt;BR /&gt;      option.)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Alex.</description>
      <pubDate>Fri, 02 Sep 2005 16:09:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617942#M104629</guid>
      <dc:creator>Alex Lavrov.</dc:creator>
      <dc:date>2005-09-02T16:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: while loop exits after call to ssh</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617943#M104630</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I agree with Alex, -n resolves the problem&lt;BR /&gt;&lt;BR /&gt;HTH</description>
      <pubDate>Fri, 02 Sep 2005 16:22:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617943#M104630</guid>
      <dc:creator>Victor Fridyev</dc:creator>
      <dc:date>2005-09-02T16:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: while loop exits after call to ssh</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617944#M104631</link>
      <description>I've done a quick test and it looks good.  I'll foward it on to the DBAs and see if it works.  I had noticed those flags in the man page, but didn't know they'd apply to me.</description>
      <pubDate>Fri, 02 Sep 2005 16:50:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617944#M104631</guid>
      <dc:creator>Kevin Nikiforuk</dc:creator>
      <dc:date>2005-09-02T16:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: while loop exits after call to ssh</title>
      <link>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617945#M104632</link>
      <description>Clearly there are some very good answers in this thread. So much so, that I bookmarked it.&lt;BR /&gt;&lt;BR /&gt;Please take the time to assign points to all answers and high points to the answers that magically solved the problem.&lt;BR /&gt;&lt;BR /&gt;From: the peanut gallery.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Sat, 03 Sep 2005 14:30:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/while-loop-exits-after-call-to-ssh/m-p/3617945#M104632</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2005-09-03T14:30:17Z</dc:date>
    </item>
  </channel>
</rss>

