<?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 with flags in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/script-with-flags/m-p/5017600#M96825</link>
    <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I would just set a condition to send mail or not in the check routines and check that condition later. E.g.:&lt;BR /&gt;...&lt;BR /&gt;ABCD)&lt;BR /&gt;if [ $pcent -lt 15 ]; then&lt;BR /&gt;find $TMPDIR -type f -mtime +30 -exec rm -f {} \; #if flags are older than a month remove&lt;BR /&gt;sendit=y  # preset condition&lt;BR /&gt;if [ -f $TMPDIR/$name.2 ]; then&lt;BR /&gt;sendit=   # change condition&lt;BR /&gt;elif [ -f $TMPDIR/$name.1 ]; then&lt;BR /&gt;touch $TMPDIR/$name.2&lt;BR /&gt;else&lt;BR /&gt;touch $TMPDIR/$name.1&lt;BR /&gt;fi&lt;BR /&gt;#   check condition&lt;BR /&gt;[ "$sendit" ] &amp;amp;&amp;amp;&lt;BR /&gt;mail -t $maila &amp;lt;&lt;EOF&gt;&lt;/EOF&gt;Subject: $mailsubj&lt;BR /&gt;From: $name&lt;BR /&gt;Cc: $dbagroup&lt;BR /&gt;message body&lt;BR /&gt;EOF&lt;BR /&gt;fi&lt;BR /&gt;;;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
    <pubDate>Thu, 07 Dec 2006 14:41:56 GMT</pubDate>
    <dc:creator>Peter Nikitka</dc:creator>
    <dc:date>2006-12-07T14:41:56Z</dc:date>
    <item>
      <title>Script with flags</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-with-flags/m-p/5017599#M96824</link>
      <description>Hi all,&lt;BR /&gt;I have a script that does a daily check of a file.  If it finds a certain condition, it will email.  However, I only want it to email twice.  So it will check for flag1 and if it exists it checks for flag2.  If both exist, I want it not to email.  Here is what I have...it is part of a case statement:&lt;BR /&gt;&lt;BR /&gt;ABCD)&lt;BR /&gt;if [ $pcent -lt 15 ]; then&lt;BR /&gt;find $TMPDIR -type f -mtime +30 -exec rm -f {} \;  #if flags are older than a month remove &lt;BR /&gt;if [ -f $TMPDIR/$name.2 ]; then&lt;BR /&gt;  HERE IS WHERE I AM STUCK&lt;BR /&gt;elif [ -f $TMPDIR/$name.1 ]; then&lt;BR /&gt;  touch $TMPDIR/$name.2&lt;BR /&gt;else&lt;BR /&gt;  touch $TMPDIR/$name.1&lt;BR /&gt;fi&lt;BR /&gt;mail -t $maila &amp;lt;&lt;EOF&gt;&lt;/EOF&gt;Subject: $mailsubj&lt;BR /&gt;From: $name&lt;BR /&gt;Cc: $dbagroup&lt;BR /&gt;message body&lt;BR /&gt;EOF&lt;BR /&gt;fi&lt;BR /&gt;;;&lt;BR /&gt;&lt;BR /&gt;DEFG)&lt;BR /&gt;same as above&lt;BR /&gt;EOF&lt;BR /&gt;;;&lt;BR /&gt;&lt;BR /&gt;So my problem is that it works great if no flags exist or only flag1.  I don't know what to do when it finds both flags.  I had "exit" but then the script stops and it doesn't run through the other cases.  I had echo "nothing" to /dev/null but then it still emails.  I guess I could put the whole email spiel in each if statement, but just thought I would check with you guys to see if there is something much simpler I could be doing.&lt;BR /&gt;&lt;BR /&gt;Thanks!</description>
      <pubDate>Thu, 07 Dec 2006 14:31:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-with-flags/m-p/5017599#M96824</guid>
      <dc:creator>Coolmar</dc:creator>
      <dc:date>2006-12-07T14:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Script with flags</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-with-flags/m-p/5017600#M96825</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I would just set a condition to send mail or not in the check routines and check that condition later. E.g.:&lt;BR /&gt;...&lt;BR /&gt;ABCD)&lt;BR /&gt;if [ $pcent -lt 15 ]; then&lt;BR /&gt;find $TMPDIR -type f -mtime +30 -exec rm -f {} \; #if flags are older than a month remove&lt;BR /&gt;sendit=y  # preset condition&lt;BR /&gt;if [ -f $TMPDIR/$name.2 ]; then&lt;BR /&gt;sendit=   # change condition&lt;BR /&gt;elif [ -f $TMPDIR/$name.1 ]; then&lt;BR /&gt;touch $TMPDIR/$name.2&lt;BR /&gt;else&lt;BR /&gt;touch $TMPDIR/$name.1&lt;BR /&gt;fi&lt;BR /&gt;#   check condition&lt;BR /&gt;[ "$sendit" ] &amp;amp;&amp;amp;&lt;BR /&gt;mail -t $maila &amp;lt;&lt;EOF&gt;&lt;/EOF&gt;Subject: $mailsubj&lt;BR /&gt;From: $name&lt;BR /&gt;Cc: $dbagroup&lt;BR /&gt;message body&lt;BR /&gt;EOF&lt;BR /&gt;fi&lt;BR /&gt;;;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Thu, 07 Dec 2006 14:41:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-with-flags/m-p/5017600#M96825</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-12-07T14:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Script with flags</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-with-flags/m-p/5017601#M96826</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;There are several ways here.  One way is to rearrange your code similar to:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;if   [ ! -f "$name.1" ]; then&lt;BR /&gt;    touch $name.1&lt;BR /&gt;elif [ ! -f "$name.2" ]; then&lt;BR /&gt;    touch $name.2&lt;BR /&gt;else&lt;BR /&gt;    mail ...&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Dec 2006 14:49:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-with-flags/m-p/5017601#M96826</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-12-07T14:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: Script with flags</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-with-flags/m-p/5017602#M96827</link>
      <description>You need to discover the shell's logical and and logical or:&lt;BR /&gt;&lt;BR /&gt;Classic syntax:&lt;BR /&gt;&lt;BR /&gt;if [ -f ${TMPDIR}/${name}.1 -o -f ${TMPDIR}/${name}.2 ] # -o =&amp;gt; OR&lt;BR /&gt;  then&lt;BR /&gt;    # at least one file was found&lt;BR /&gt;  else&lt;BR /&gt;    if [ -f ${TMPDIR}/${name}.1 -a -f ${TMPDIR}/${name}.2 ] # -a =&amp;gt; AND&lt;BR /&gt;      then &lt;BR /&gt;        # both were found&lt;BR /&gt;      else&lt;BR /&gt;        if [ -f ${TMPDIR}/${name}.1 ]&lt;BR /&gt;          then&lt;BR /&gt;            # only file1 was found&lt;BR /&gt;          else&lt;BR /&gt;            # only file2 was found&lt;BR /&gt;          fi&lt;BR /&gt;      fi&lt;BR /&gt;  else&lt;BR /&gt;    # No files were found&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Newer more efficient equivalent syntax for Korn and POSIX shell syntax (Note the double ]]'s and [['s meaning the shell evaluates internally rather than using the external test command.):&lt;BR /&gt;&lt;BR /&gt;if [[ -f ${TMPDIR}/${name}.1 || -f ${TMPDIR}/${name}.2 ]] # || =&amp;gt; OR&lt;BR /&gt;  then&lt;BR /&gt;    # at least one file was found&lt;BR /&gt;  else&lt;BR /&gt;    if [[ -f ${TMPDIR}/${name}.1 &amp;amp;&amp;amp; -f ${TMPDIR}/${name}.2 ]] # &amp;amp;&amp;amp; =&amp;gt; AND&lt;BR /&gt;      then &lt;BR /&gt;        # both were found&lt;BR /&gt;      else&lt;BR /&gt;        if [[ -f ${TMPDIR}/${name}.1 ]]&lt;BR /&gt;          then&lt;BR /&gt;            # only file1 was found&lt;BR /&gt;          else&lt;BR /&gt;            # only file2 was found&lt;BR /&gt;          fi&lt;BR /&gt;      fi&lt;BR /&gt;  else&lt;BR /&gt;    # No files were found&lt;BR /&gt;  fi&lt;BR /&gt;          &lt;BR /&gt;</description>
      <pubDate>Thu, 07 Dec 2006 14:50:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-with-flags/m-p/5017602#M96827</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-12-07T14:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Script with flags</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-with-flags/m-p/5017603#M96828</link>
      <description>Thanks guys...that helped alot!</description>
      <pubDate>Fri, 08 Dec 2006 09:57:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-with-flags/m-p/5017603#M96828</guid>
      <dc:creator>Coolmar</dc:creator>
      <dc:date>2006-12-08T09:57:44Z</dc:date>
    </item>
  </channel>
</rss>

