<?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 help - test command in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493671#M215410</link>
    <description>Even easier:&lt;BR /&gt; &lt;BR /&gt;[ -f /var/cron/cron.allow ] &amp;amp;&amp;amp;  echo "\troot is in cron.allow" ||  echo "root\n" &amp;gt;&amp;gt; /var/adm/cron/cron.allow&lt;BR /&gt; &lt;BR /&gt;The [[ ... ]] construct is for more specialized conditions including testing undefined variables. The &amp;amp;&amp;amp; and || are shortcuts for if-then-else-fi. In your original construct, the $(test...) code is redundant because test and [...] are the same thing. See: man test</description>
    <pubDate>Fri, 25 Feb 2005 15:37:12 GMT</pubDate>
    <dc:creator>Bill Hassell</dc:creator>
    <dc:date>2005-02-25T15:37:12Z</dc:date>
    <item>
      <title>Script help - test command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493664#M215403</link>
      <description>I want to check if cron.allow exists, if so, look to see if root and oracle are in it.  If it does not exist, create it and add them.  &lt;BR /&gt;&lt;BR /&gt;Here is the script:&lt;BR /&gt;   echo "Verifying /var/adm/cron/cron.allow..."&lt;BR /&gt;   if [  $(test -f /var/adm/cron/cron.allow) ]; then&lt;BR /&gt;      if [ $(grep -q root /var/adm/cron/cron.allow) ]; then&lt;BR /&gt;         echo "\troot is in cron.allow"&lt;BR /&gt;      else&lt;BR /&gt;         echo "root\n" &amp;gt;&amp;gt; /var/adm/cron/cron.allow&lt;BR /&gt;      fi&lt;BR /&gt;      if [ $(grep -q oracle /var/adm/cron/cron.allow) ]; then&lt;BR /&gt;         echo "\toracle is in cron.allow"&lt;BR /&gt;      else&lt;BR /&gt;         echo "oracle\n" &amp;gt;&amp;gt; /var/adm/cron/cron.allow&lt;BR /&gt;      fi&lt;BR /&gt;   else&lt;BR /&gt;      echo "root\noracle\n" &amp;gt;&amp;gt; /var/adm/cron/cron.allow&lt;BR /&gt;   fi&lt;BR /&gt;   chmod 644 /var/adm/cron/cron.allow&lt;BR /&gt;   chown root:system /var/adm/cron/cron.allow&lt;BR /&gt;   echo "COMPLETED - Verifying /var/adm/cron/cron.allow.\n"&lt;BR /&gt;&lt;BR /&gt;Even if the cron.allow is there and has root and oracle in it, it is still adding them.  I know it isn't "catching" on the first "if" statement so something must be wrong with my "test" command.&lt;BR /&gt;&lt;BR /&gt;Thanks again..</description>
      <pubDate>Fri, 25 Feb 2005 12:05:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493664#M215403</guid>
      <dc:creator>Greg Stark_1</dc:creator>
      <dc:date>2005-02-25T12:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - test command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493665#M215404</link>
      <description>I would change following.&lt;BR /&gt;if [ $(test -f /var/adm/cron/cron.allow) ]; then&lt;BR /&gt;&lt;BR /&gt;to&lt;BR /&gt;if [[ -f /var/adm/cron/cron.allow ]];then&lt;BR /&gt;&lt;BR /&gt;your code.&lt;BR /&gt;&lt;BR /&gt;Also grep statements as follows.&lt;BR /&gt;&lt;BR /&gt;stat=$?&lt;BR /&gt;root=$(grep -i root /var/adm/cron/cron.allow &amp;gt; /dev/null 2&amp;gt;&amp;amp;1)&lt;BR /&gt;if [[ ${stat} -ne "0" ]];then&lt;BR /&gt;echo "root\n" &amp;gt;&amp;gt; /var/adm/cron/cron.allow&lt;BR /&gt;&lt;BR /&gt;Anil</description>
      <pubDate>Fri, 25 Feb 2005 12:09:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493665#M215404</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2005-02-25T12:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - test command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493666#M215405</link>
      <description>Hi &lt;BR /&gt;&lt;BR /&gt;change your test command from :&lt;BR /&gt;if [ $(test -f /var/adm/cron/cron.allow) ]; then&lt;BR /&gt;&lt;BR /&gt;to&lt;BR /&gt;if [[ -f /var/adm/cron/cron.allow ]]; then&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Jean-Luc</description>
      <pubDate>Fri, 25 Feb 2005 12:12:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493666#M215405</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2005-02-25T12:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - test command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493667#M215406</link>
      <description>You need&lt;BR /&gt; to change your syntax:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;FNAME="/var/adm/cron/cron.allow"&lt;BR /&gt;&lt;BR /&gt;if [[ -f ${FNAME} ]]&lt;BR /&gt;  then&lt;BR /&gt;    grep -q "root" S{FNAME}&lt;BR /&gt;    STAT=${?}&lt;BR /&gt;    if [[ ${STAT} -eq 0 ]]&lt;BR /&gt;      then&lt;BR /&gt;        echo "root found"&lt;BR /&gt;      else&lt;BR /&gt;        echo "root not found"&lt;BR /&gt;      fi&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;Note the use of the [['s and ]]'s in lieu of the more traditional ['s and ]'s. The double brackets utilize the shell's internal tests rather than relying upon the external test command. Under this syntax logical and's are &amp;amp;&amp;amp; (rather than -a) and logical or's are || (rather than -o). grep -q returns a zero result when a match is found and non-zero otherwise.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 25 Feb 2005 12:14:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493667#M215406</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-02-25T12:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - test command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493668#M215407</link>
      <description>Hey Greg,&lt;BR /&gt;Here's a VERY simple way to check for cron.allow and add root and oracle:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;FILE="/var/adm/cron/cron.allow"&lt;BR /&gt;MODF="$FILE.$$.mod"&lt;BR /&gt; if [[ -f "$FILE" ]]; then&lt;BR /&gt;  egrep -v "^root|^oracle" $FILE &amp;gt;$MODF&lt;BR /&gt;  echo "root" &amp;gt;&amp;gt; $MODF&lt;BR /&gt;  echo "oracle" &amp;gt;&amp;gt; $MODF&lt;BR /&gt;  cp -p $MODF $FILE&lt;BR /&gt; else&lt;BR /&gt;  echo root &amp;gt; $FILE&lt;BR /&gt;  echo oracle &amp;gt;&amp;gt; $FILE&lt;BR /&gt; fi</description>
      <pubDate>Fri, 25 Feb 2005 15:20:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493668#M215407</guid>
      <dc:creator>Dani Seely</dc:creator>
      <dc:date>2005-02-25T15:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - test command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493669#M215408</link>
      <description>Hey Greg,&lt;BR /&gt;The script I provided is short and simple and I'm sure it will work for you.  Also, I hit submit before I remembered the rest of your message.  You are setting permissions of your cron.allow file a little loose.  If you are security consciencious, you should set permissions to 700.&lt;BR /&gt;&lt;BR /&gt;Also, the owner and group should be root, bin, or sys (you show root:system ... I think you want root:sys unless you renamed the sys group to system or created a system group.)</description>
      <pubDate>Fri, 25 Feb 2005 15:32:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493669#M215408</guid>
      <dc:creator>Dani Seely</dc:creator>
      <dc:date>2005-02-25T15:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - test command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493670#M215409</link>
      <description>Sorry, one more thing ...&lt;BR /&gt;&lt;BR /&gt;Do you have a cron.deny file?  If there is a cron.deny file and the cron.deny file has the default accounts in it, the cron.allow file does not have to exist.</description>
      <pubDate>Fri, 25 Feb 2005 15:35:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493670#M215409</guid>
      <dc:creator>Dani Seely</dc:creator>
      <dc:date>2005-02-25T15:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - test command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493671#M215410</link>
      <description>Even easier:&lt;BR /&gt; &lt;BR /&gt;[ -f /var/cron/cron.allow ] &amp;amp;&amp;amp;  echo "\troot is in cron.allow" ||  echo "root\n" &amp;gt;&amp;gt; /var/adm/cron/cron.allow&lt;BR /&gt; &lt;BR /&gt;The [[ ... ]] construct is for more specialized conditions including testing undefined variables. The &amp;amp;&amp;amp; and || are shortcuts for if-then-else-fi. In your original construct, the $(test...) code is redundant because test and [...] are the same thing. See: man test</description>
      <pubDate>Fri, 25 Feb 2005 15:37:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-test-command/m-p/3493671#M215410</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-02-25T15:37:12Z</dc:date>
    </item>
  </channel>
</rss>

