<?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: $? from su in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067494#M904604</link>
    <description>Probably the easiest thing to do is each time you call su write a message with the return status to a logfile in /tmp, eg;&lt;BR /&gt;&lt;BR /&gt;su - &lt;USER&gt; -c "&lt;START app=""&gt;;echo started app return status = $? &amp;gt;&amp;gt;/tmp/log"&lt;BR /&gt;&lt;BR /&gt;Then check the log afterwards.&lt;BR /&gt;&lt;/START&gt;&lt;/USER&gt;</description>
    <pubDate>Wed, 10 Sep 2003 09:46:30 GMT</pubDate>
    <dc:creator>Stefan Farrelly</dc:creator>
    <dc:date>2003-09-10T09:46:30Z</dc:date>
    <item>
      <title>$? from su</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067492#M904602</link>
      <description>Hello!&lt;BR /&gt;&lt;BR /&gt;I use a script to start several applications. Each application is started with a different user, using the su - &lt;USER&gt; command.&lt;BR /&gt;I would like to get within the main script the exit status of the command used within the su to start the application.&lt;BR /&gt;How can I do it?&lt;/USER&gt;</description>
      <pubDate>Wed, 10 Sep 2003 09:37:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067492#M904602</guid>
      <dc:creator>Sylvain CROUET</dc:creator>
      <dc:date>2003-09-10T09:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: $? from su</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067493#M904603</link>
      <description>Try the following:&lt;BR /&gt;&lt;BR /&gt;su -c "&lt;COMMAND&gt;;[[ $? -eq 0 ]] &amp;amp;&amp;amp; echo ok" &lt;USERID&gt;&lt;BR /&gt;&lt;BR /&gt;I'm nowhere near a server so I might have the syntax a bit screwed, but the concept should work.  :-)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Tim&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/USERID&gt;&lt;/COMMAND&gt;</description>
      <pubDate>Wed, 10 Sep 2003 09:43:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067493#M904603</guid>
      <dc:creator>Tim Adamson_1</dc:creator>
      <dc:date>2003-09-10T09:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: $? from su</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067494#M904604</link>
      <description>Probably the easiest thing to do is each time you call su write a message with the return status to a logfile in /tmp, eg;&lt;BR /&gt;&lt;BR /&gt;su - &lt;USER&gt; -c "&lt;START app=""&gt;;echo started app return status = $? &amp;gt;&amp;gt;/tmp/log"&lt;BR /&gt;&lt;BR /&gt;Then check the log afterwards.&lt;BR /&gt;&lt;/START&gt;&lt;/USER&gt;</description>
      <pubDate>Wed, 10 Sep 2003 09:46:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067494#M904604</guid>
      <dc:creator>Stefan Farrelly</dc:creator>
      <dc:date>2003-09-10T09:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: $? from su</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067495#M904605</link>
      <description>On second thought how about;&lt;BR /&gt;&lt;BR /&gt;su - &lt;USERID&gt; -c "&lt;START app=""&gt;;[[ $? -ne 0 ]] &amp;amp;&amp;amp; exit $?"&lt;BR /&gt;[ $? -ne 0 ] &amp;amp;&amp;amp; echo bad return status from trying to start application &lt;APP&gt;&lt;BR /&gt;&lt;BR /&gt;This will return any bad return status from the start app command back to the su command to so you can check for the value of $? immediately after the su.&lt;BR /&gt;&lt;/APP&gt;&lt;/START&gt;&lt;/USERID&gt;</description>
      <pubDate>Wed, 10 Sep 2003 09:50:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067495#M904605</guid>
      <dc:creator>Stefan Farrelly</dc:creator>
      <dc:date>2003-09-10T09:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: $? from su</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067496#M904606</link>
      <description>Well, this may be tricky. If su - fails (like a bad password) then you'll get a non-zero exit code from su - (like 9 for bad password, 13 for badlogin)).  However, if su - is successful, it will start the user's shell and run whatever you have in your script. But then the return code may contain the exit code of the task rather than su.  SO you may need to code a special flag (a zero length file for instance) to signal your parent script that all is well with su.</description>
      <pubDate>Wed, 10 Sep 2003 09:55:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067496#M904606</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2003-09-10T09:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: $? from su</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067497#M904607</link>
      <description>I thought su returned the exit code of whatever it ran anyway? As in the following examples:&lt;BR /&gt;&lt;BR /&gt;# su oracle -c true&lt;BR /&gt;# echo $?&lt;BR /&gt;0&lt;BR /&gt;# su oracle -c false&lt;BR /&gt;# echo $?&lt;BR /&gt;1&lt;BR /&gt;# su oracle -c "exit 3"&lt;BR /&gt;# echo $?&lt;BR /&gt;3&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Duncan</description>
      <pubDate>Wed, 10 Sep 2003 09:57:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067497#M904607</guid>
      <dc:creator>Duncan Edmonstone</dc:creator>
      <dc:date>2003-09-10T09:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: $? from su</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067498#M904608</link>
      <description>Thanks!&lt;BR /&gt;&lt;BR /&gt;In fact the only solution I already found was the temporary file containing the exit status, solution proposed by Stefan. I hoped there was a better solution.&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Sep 2003 06:53:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067498#M904608</guid>
      <dc:creator>Sylvain CROUET</dc:creator>
      <dc:date>2003-09-11T06:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: $? from su</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067499#M904609</link>
      <description>I'm facing a similar problem so I tried Duncan's solution.  However, I noticed that the return value was always 0 for one of the users.  Turns out this user has a different shell (PEEK shell) than the others.  So, for /sbin/sh and /usr/bin/sh I was able to get "su - &lt;USER&gt; -c 'exit 3'" to return 3.&lt;BR /&gt;&lt;BR /&gt;Bill, though I understand what's happening in the case of the PEEK shell, why would su sometimes return the task exit code instead of the command code?&lt;BR /&gt;&lt;BR /&gt;Wouldn't Tim's or Stefan's solution handle that by making the task's exit code be the command's exit code?&lt;BR /&gt;&lt;BR /&gt;Just curious (sorry for the follow-on!).&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Seth&lt;/USER&gt;</description>
      <pubDate>Thu, 11 Sep 2003 16:59:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/from-su/m-p/3067499#M904609</guid>
      <dc:creator>Seth Parker</dc:creator>
      <dc:date>2003-09-11T16:59:41Z</dc:date>
    </item>
  </channel>
</rss>

