<?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: Script explanation in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-explanation/m-p/5732077#M638375</link>
    <description>&lt;P&gt;If the return code of the 'tty -s' command is 0, which means you are logged in with a terminal session and NOT running via cron, &lt;STRONG&gt;and&lt;/STRONG&gt; you are NOT logged in as root then the script will exit with a return code of 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Jul 2012 13:22:38 GMT</pubDate>
    <dc:creator>Patrick Wallek</dc:creator>
    <dc:date>2012-07-20T13:22:38Z</dc:date>
    <item>
      <title>Script explanation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-explanation/m-p/5731765#M638374</link>
      <description>&lt;P&gt;What is the explanation of the below script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#======= patrol user profile =======&lt;BR /&gt;LANG=C; export LANG&lt;BR /&gt;MAIL=/usr/mail/${LOGNAME:?}&lt;BR /&gt;tty -s&lt;BR /&gt;if [ $? -eq 0 ]&lt;BR /&gt;then&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if [ `logname` != "root" ]&lt;BR /&gt;&amp;nbsp;&amp;nbsp; then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit 1&lt;BR /&gt;&amp;nbsp;&amp;nbsp; fi&lt;BR /&gt;fi&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2012 09:29:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-explanation/m-p/5731765#M638374</guid>
      <dc:creator>Ajin_1</dc:creator>
      <dc:date>2012-07-20T09:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: Script explanation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-explanation/m-p/5732077#M638375</link>
      <description>&lt;P&gt;If the return code of the 'tty -s' command is 0, which means you are logged in with a terminal session and NOT running via cron, &lt;STRONG&gt;and&lt;/STRONG&gt; you are NOT logged in as root then the script will exit with a return code of 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2012 13:22:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-explanation/m-p/5732077#M638375</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2012-07-20T13:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: Script explanation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-explanation/m-p/5732081#M638376</link>
      <description>&lt;PRE&gt;# Set the locale variable LANG to C and export it
# (locale C means "classic unix processing: no particular localization,
# all error messages in US English and character set US-ASCII only)
LANG=C; export LANG

# If the environment variable LOGNAME contains a value, set
# variable MAIL to /usr/mail/&amp;lt;value of LOGNAME&amp;gt;. 
# If LOGNAME is not set, exit.
MAIL=/usr/mail/${LOGNAME:?}

# Test silently if the script is associated with a terminal.
# If not (= the script is run non-interactively as a cron job or
# some other background process, or its standard input has been
# redirected), the result code $? will be set to
# a non-zero value.
tty -s

# Test the result code of the previous command. If it was zero,
# run the commands between the outermost "then" and the outermost "fi".
if [ $? -eq 0 ]
then

   # This will be executed only if the result code from the "tty -s" was
   # zero, i.e. the script is running with a terminal. 
   # Run the command "logname" (which returns the current username)
   # and examine it's output.
   # If the output is something other than "root", run the commands
   # between the inner "then" and inner "fi".
   if [ `logname` != "root" ]
   then

      # This will be executed only if the script is running with a
      # terminal and the current username was not "root".
      # This command will exit the script with result code 1.
      exit 1
   fi
fi&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first two lines are primarily for setting up some environment settings, and the rest seems to be trying to&lt;/P&gt;&lt;P&gt;stop the script if it is not run by the root user.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this script has been named as ".profile" in the patrol user's home directory, this would prevent logging in as the "patrol" user, but would allow root to use the "su", "sudo" or similar commands to switch to "patrol" user. If someone tried to log in as user "patrol", the session would immediately end.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2012 13:24:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-explanation/m-p/5732081#M638376</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2012-07-20T13:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Script explanation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-explanation/m-p/5732083#M638377</link>
      <description>&lt;P&gt;&amp;gt;MAIL=/usr/mail/${LOGNAME:?}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hmm, I would have thought it should be /var/mail/.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can optimize the two "if"s to:&lt;/P&gt;&lt;P&gt;if [ $? -eq 0 -a $(logname) != "root" ];&amp;nbsp; then&lt;BR /&gt;&amp;nbsp;&amp;nbsp; exit 1&lt;/P&gt;&lt;P&gt;fi&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2012 13:26:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-explanation/m-p/5732083#M638377</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-07-20T13:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Script explanation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-explanation/m-p/5732467#M638378</link>
      <description>&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;MAIL=/usr/mail/${LOGNAME:?}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;Hmm, I would have thought it should be /var/mail/.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/usr/mail is a symbolic link (transition link) to /var/mail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;root /usr # ls -ld mail&lt;BR /&gt;lrwxrwxrwt&amp;nbsp;&amp;nbsp; 1 root&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sys&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9 Jun 30&amp;nbsp; 2011 mail -&amp;gt; /var/mail&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2012 19:10:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-explanation/m-p/5732467#M638378</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2012-07-20T19:10:08Z</dc:date>
    </item>
  </channel>
</rss>

