<?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: Looping in a script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176050#M682341</link>
    <description>&lt;!--!*#--&gt;&amp;gt;Doug: while [ "${b}" = "&lt;PATTERN&gt;" ]&lt;BR /&gt;&lt;BR /&gt;If you want a pattern instead of a simple string compare, you must use [[ ]].  And if you have a pattern, you must not use "".&lt;BR /&gt;&lt;BR /&gt;&amp;gt;JRF: (1) Eliminate useless 'cat' processes!&lt;BR /&gt;&lt;BR /&gt;Any reason you left this one? ;-)&lt;BR /&gt;a=$(cat ${MYLOG}|head -n 5|sed 's/^.{45}//' &amp;gt; ${MYNOT})&lt;BR /&gt;&lt;BR /&gt;You could reverse the logic and save an indent for the main logic:&lt;BR /&gt;    if [[ $b != &lt;PATTERN&gt; ]]; then&lt;BR /&gt;        break&lt;BR /&gt;    fi&lt;BR /&gt;    mailx -s "CDR backup is completed in blbilstg server" ${MAILTO} &amp;lt; ${MYNOT}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PATTERN&gt;&lt;/PATTERN&gt;</description>
    <pubDate>Tue, 19 May 2009 16:06:52 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2009-05-19T16:06:52Z</dc:date>
    <item>
      <title>Looping in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176041#M682332</link>
      <description>I have a script which is ran to get a file from ftp site and manipulate it. but the file is overwritten and match with the pattern. if pattern found then do some jobs. here is that&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;function ftps {&lt;BR /&gt;sleep 20&lt;BR /&gt;USER=anonymous&lt;BR /&gt;PW=xxxxx&lt;BR /&gt;ftp -v -i -n &lt;SERVER_NAME&gt; &amp;lt;&amp;lt; EOF&lt;BR /&gt;user $USER $PW&lt;BR /&gt;ascii&lt;BR /&gt;mget notification.log&lt;BR /&gt;bye&lt;BR /&gt;EOF&lt;BR /&gt;}&lt;BR /&gt;ftps&lt;BR /&gt;MAIL_RECEIVER="&lt;EMAIL&gt;"&lt;BR /&gt;a=`cat notification.log |head -n 5|sed 's/^.............................................//' &amp;gt; file.not.tmp`&lt;BR /&gt;b=`cat file.not.tmp |awk '{print $4}'`&lt;BR /&gt;if [[ $b = "&lt;PATTERN&gt;" ]]&lt;BR /&gt;then&lt;BR /&gt;mailx -s "CDR backup is completed in blbilstg server" $MAIL_RECEIVER &amp;lt; file.not.tmp&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;The scripts seems ok if the pattern is matched. But my concern is, I want to run the script until the pattern is not matched.&lt;/PATTERN&gt;&lt;/EMAIL&gt;&lt;/SERVER_NAME&gt;</description>
      <pubDate>Tue, 19 May 2009 11:13:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176041#M682332</guid>
      <dc:creator>Jeeshan</dc:creator>
      <dc:date>2009-05-19T11:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176042#M682333</link>
      <description>Hey;&lt;BR /&gt;&lt;BR /&gt;If I'm understanding you correctly, you should be able to change the if statement at the end to&lt;BR /&gt;&lt;BR /&gt;while [ "${b}" = "&lt;PATTER&gt;" ]&lt;BR /&gt;do&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;I'd caution against this implemenetation, though.  You're setting yourself up for problems if the file gets overwritten while it's being processed, if the ftp fails for any reason, etc.&lt;BR /&gt;&lt;BR /&gt;HTH;&lt;BR /&gt;&lt;BR /&gt;Doug O'Leary&lt;/PATTER&gt;</description>
      <pubDate>Tue, 19 May 2009 11:25:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176042#M682333</guid>
      <dc:creator>Doug O'Leary</dc:creator>
      <dc:date>2009-05-19T11:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176043#M682334</link>
      <description>&lt;!--!*#--&gt;Hi Ahsan:&lt;BR /&gt;&lt;BR /&gt;There are several ways to do this.  One way is to use a 'true' loop and 'break' out of it when the condition you want to see is satisfied:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;function ftps {&lt;BR /&gt;    sleep 20&lt;BR /&gt;    USER=anonymous&lt;BR /&gt;    PW=xxxxx&lt;BR /&gt;    ftp -v -i -n server_name &amp;lt;&amp;lt; EOF&lt;BR /&gt;user $USER $PW&lt;BR /&gt;ascii&lt;BR /&gt;mget notification.log&lt;BR /&gt;bye&lt;BR /&gt;EOF&lt;BR /&gt;}&lt;BR /&gt;ftps&lt;BR /&gt;MAIL_RECEIVER="&lt;EMAIL&gt;"&lt;BR /&gt;a=`cat notification.log |head -n 5|sed 's/^.............................................//' &amp;gt; file.not.tmp`&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;    b=`cat file.not.tmp |awk '{print $4}'`&lt;BR /&gt;    if [[ $b = "&lt;PATTERN&gt;" ]]&lt;BR /&gt;    then&lt;BR /&gt;        mailx -s "CDR backup is completed in blbilstg server" $MAIL_RECEIVER &amp;lt; file.not.tmp&lt;BR /&gt;        break&lt;BR /&gt;    fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;...Now, let's make some improvements to your general script.  (1) Eliminate useless 'cat' processes!  (2) the 'sed' match can be made much more readable with a repeat part; (3) eliminate the backticks and use the clearer POSIX shell $() notation for command execution:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;function ftps {&lt;BR /&gt;sleep 20&lt;BR /&gt;USER=anonymous&lt;BR /&gt;PW=xxxxx&lt;BR /&gt;ftp -v -i -n server_name &amp;lt;&amp;lt; EOF&lt;BR /&gt;user $USER $PW&lt;BR /&gt;ascii&lt;BR /&gt;mget notification.log&lt;BR /&gt;bye&lt;BR /&gt;EOF&lt;BR /&gt;}&lt;BR /&gt;ftps&lt;BR /&gt;MAIL_RECEIVER="&lt;EMAIL&gt;"&lt;BR /&gt;a=$(cat notification.log |head -n 5|sed 's/^.{45}//' &amp;gt; file.not.tmp)&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;    b=$(awk '{print $4}' file.not.tmp)&lt;BR /&gt;    if [[ $b = "&lt;PATTERN&gt;" ]]&lt;BR /&gt;    then&lt;BR /&gt;        mailx -s "CDR backup is completed in blbilstg server" $MAIL_RECEIVER &amp;lt; file.not.tmp&lt;BR /&gt;        break&lt;BR /&gt;    fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/PATTERN&gt;&lt;/EMAIL&gt;&lt;/PATTERN&gt;&lt;/EMAIL&gt;</description>
      <pubDate>Tue, 19 May 2009 11:27:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176043#M682334</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-05-19T11:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176044#M682335</link>
      <description>thanks for your inputs.&lt;BR /&gt;&lt;BR /&gt;My concern is notification.log is overwritten and i do want to do ftp again until the pattern is matched.</description>
      <pubDate>Tue, 19 May 2009 11:38:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176044#M682335</guid>
      <dc:creator>Jeeshan</dc:creator>
      <dc:date>2009-05-19T11:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176045#M682336</link>
      <description>Hi (again) Ahsan:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; My concern is notification.log is overwritten and i do want to do ftp again until the pattern is matched.&lt;BR /&gt;&lt;BR /&gt;Since you are getting (with FTP) and then parsing this file, I would remove the file before performing the FTP.  This also serves as a success-or-failure test:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;rm -f notification.log&lt;BR /&gt;ftps&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;By the way, since you reference this file name multiple times, you should consider making it the value of a variable:&lt;BR /&gt;&lt;BR /&gt;MYLOG=notification.log&lt;BR /&gt;...&lt;BR /&gt;rm -r ${MYLOG}&lt;BR /&gt;ftps&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Too, I fail to see why you are using 'mget' instead of a simple 'get'.  You aren't globbing for multiple files.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Tue, 19 May 2009 11:51:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176045#M682336</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-05-19T11:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176046#M682337</link>
      <description>Yeah JRF, you are right, I should not suppose to mget instead of get.&lt;BR /&gt;&lt;BR /&gt;BTW, where i can put this rm then ftps lines?</description>
      <pubDate>Tue, 19 May 2009 12:02:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176046#M682337</guid>
      <dc:creator>Jeeshan</dc:creator>
      <dc:date>2009-05-19T12:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176047#M682338</link>
      <description>&lt;!--!*#--&gt;Hi (again) Ahsan:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; BTW, where i can put this rm then ftps lines?&lt;BR /&gt;&lt;BR /&gt;As I showed, before the ftps() call.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;set -u&lt;BR /&gt;typeset MYLOG=notification.log&lt;BR /&gt;typeset MYNOT=file.not.tmp&lt;BR /&gt;typeset MAILTO="you@your.net"&lt;BR /&gt;function ftps {&lt;BR /&gt;sleep 20&lt;BR /&gt;USER=anonymous&lt;BR /&gt;PW=xxxxx&lt;BR /&gt;ftp -v -i -n server_name &amp;lt;&amp;lt; EOF&lt;BR /&gt;user ${USER} ${PW}&lt;BR /&gt;ascii&lt;BR /&gt;get ${MYLOG}&lt;BR /&gt;bye&lt;BR /&gt;EOF&lt;BR /&gt;}&lt;BR /&gt;rm -f ${MYLOG}&lt;BR /&gt;ftps&lt;BR /&gt;a=$(cat ${MYLOG}|head -n 5|sed 's/^.{45}//' &amp;gt; ${MYNOT})&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;    b=$(awk '{print $4}' ${MYNOT})&lt;BR /&gt;    if [[ $b = "&lt;PATTERN&gt;" ]]&lt;BR /&gt;    then&lt;BR /&gt;        mailx -s "CDR backup is completed in blbilstg server" ${MAILTO} &amp;lt; ${MYNOT}&lt;BR /&gt;        break&lt;BR /&gt;    fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/PATTERN&gt;</description>
      <pubDate>Tue, 19 May 2009 12:14:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176047#M682338</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-05-19T12:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176048#M682339</link>
      <description>thanks again.&lt;BR /&gt;&lt;BR /&gt;But i want if the pattern is not matched it again ftp the file and check accordingly until the matched found. If matched found than the program will terminate.</description>
      <pubDate>Tue, 19 May 2009 12:52:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176048#M682339</guid>
      <dc:creator>Jeeshan</dc:creator>
      <dc:date>2009-05-19T12:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176049#M682340</link>
      <description>&lt;!--!*#--&gt;Hi (again):&lt;BR /&gt;&lt;BR /&gt;OK, your loop could look like this:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;    rm -f ${MYLOG}&lt;BR /&gt;    ftps&lt;BR /&gt;    a=$(cat ${MYLOG}|head -n 5|sed 's/^.{45}//' &amp;gt; ${MYNOT})&lt;BR /&gt;    b=$(awk '{print $4}' ${MYNOT})&lt;BR /&gt;    if [[ $b = "&lt;PATTERN&gt;" ]]&lt;BR /&gt;    then&lt;BR /&gt;        mailx -s "CDR backup is completed in blbilstg server" ${MAILTO} &amp;lt; ${MYNOT}&lt;BR /&gt;        continue&lt;BR /&gt;    else&lt;BR /&gt;        break&lt;BR /&gt;    fi&lt;BR /&gt;done&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/PATTERN&gt;</description>
      <pubDate>Tue, 19 May 2009 13:18:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176049#M682340</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-05-19T13:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176050#M682341</link>
      <description>&lt;!--!*#--&gt;&amp;gt;Doug: while [ "${b}" = "&lt;PATTERN&gt;" ]&lt;BR /&gt;&lt;BR /&gt;If you want a pattern instead of a simple string compare, you must use [[ ]].  And if you have a pattern, you must not use "".&lt;BR /&gt;&lt;BR /&gt;&amp;gt;JRF: (1) Eliminate useless 'cat' processes!&lt;BR /&gt;&lt;BR /&gt;Any reason you left this one? ;-)&lt;BR /&gt;a=$(cat ${MYLOG}|head -n 5|sed 's/^.{45}//' &amp;gt; ${MYNOT})&lt;BR /&gt;&lt;BR /&gt;You could reverse the logic and save an indent for the main logic:&lt;BR /&gt;    if [[ $b != &lt;PATTERN&gt; ]]; then&lt;BR /&gt;        break&lt;BR /&gt;    fi&lt;BR /&gt;    mailx -s "CDR backup is completed in blbilstg server" ${MAILTO} &amp;lt; ${MYNOT}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PATTERN&gt;&lt;/PATTERN&gt;</description>
      <pubDate>Tue, 19 May 2009 16:06:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176050#M682341</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-05-19T16:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176051#M682342</link>
      <description>HI:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Dennis: &amp;gt;JRF: (1) Eliminate useless 'cat' processes! Any reason you left this one? ;-)&lt;BR /&gt;&lt;BR /&gt;Yeah, I was focused on the 'sed' and on the original backticks :-}}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Tue, 19 May 2009 16:11:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176051#M682342</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-05-19T16:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176052#M682343</link>
      <description>JRF, just a modification and it works.</description>
      <pubDate>Wed, 20 May 2009 05:46:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-in-a-script/m-p/5176052#M682343</guid>
      <dc:creator>Jeeshan</dc:creator>
      <dc:date>2009-05-20T05:46:18Z</dc:date>
    </item>
  </channel>
</rss>

