<?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: exit my scripts in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011401#M99200</link>
    <description>Sorry, forget to define CODE before "if"&lt;BR /&gt;&lt;BR /&gt;# generic check function&lt;BR /&gt;&lt;BR /&gt;CODE=0&lt;BR /&gt;&lt;BR /&gt;check () {&lt;BR /&gt;&lt;BR /&gt;if [[ $? -ne 0 ]] ; then&lt;BR /&gt;&lt;BR /&gt;logfile "Unix Alert: Error Processing sftp01 MRD files, please investigate"&lt;BR /&gt;mail -s "$DATE:$TIME:$PROGPATH/$PROGNAME has failed, please investigate" chris@mail &amp;lt;$LOGFILE&lt;BR /&gt;rm $LCKFILE&lt;BR /&gt;&lt;BR /&gt;CODE=1&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;exit $CODE&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Yang</description>
    <pubDate>Tue, 31 Oct 2006 06:48:12 GMT</pubDate>
    <dc:creator>Yang Qin_1</dc:creator>
    <dc:date>2006-10-31T06:48:12Z</dc:date>
    <item>
      <title>exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011398#M99197</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I have created a script to ftp files to and from an sftp server.&lt;BR /&gt;&lt;BR /&gt;I have a check function within the script:&lt;BR /&gt;&lt;BR /&gt;# generic check function&lt;BR /&gt;&lt;BR /&gt;check   () {&lt;BR /&gt;&lt;BR /&gt;        if [[ $? -ne 0 ]] ; then&lt;BR /&gt;&lt;BR /&gt;                logfile "Unix Alert: Error Processing sftp01 MRD files, please investigate"&lt;BR /&gt;                mail -s "$DATE:$TIME:$PROGPATH/$PROGNAME has failed, please investigate" chris@mail &amp;lt;$LOGFILE&lt;BR /&gt;                rm $LCKFILE&lt;BR /&gt;               &lt;BR /&gt;        fi&lt;BR /&gt;&lt;BR /&gt;My question is I want to then exit out of the entire script so I put exit 1 after the rm $LCKFILE but this then continued within the script.&lt;BR /&gt;&lt;BR /&gt;what is the exit code to stop the script processing completely within the check function?&lt;BR /&gt;&lt;BR /&gt;many thanks</description>
      <pubDate>Tue, 31 Oct 2006 06:28:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011398#M99197</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2006-10-31T06:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011399#M99198</link>
      <description>Try with :&lt;BR /&gt;&lt;BR /&gt;exit 127&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;ivan</description>
      <pubDate>Tue, 31 Oct 2006 06:32:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011399#M99198</guid>
      <dc:creator>Ivan Krastev</dc:creator>
      <dc:date>2006-10-31T06:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011400#M99199</link>
      <description>Try:&lt;BR /&gt;# generic check function&lt;BR /&gt;&lt;BR /&gt;check () {&lt;BR /&gt;&lt;BR /&gt;if [[ $? -ne 0 ]] ; then&lt;BR /&gt;&lt;BR /&gt;logfile "Unix Alert: Error Processing sftp01 MRD files, please investigate"&lt;BR /&gt;mail -s "$DATE:$TIME:$PROGPATH/$PROGNAME has failed, please investigate" chris@mail &amp;lt;$LOGFILE&lt;BR /&gt;rm $LCKFILE&lt;BR /&gt;&lt;BR /&gt;CODE=1&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;exit $CODE&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Yang&lt;BR /&gt;</description>
      <pubDate>Tue, 31 Oct 2006 06:46:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011400#M99199</guid>
      <dc:creator>Yang Qin_1</dc:creator>
      <dc:date>2006-10-31T06:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011401#M99200</link>
      <description>Sorry, forget to define CODE before "if"&lt;BR /&gt;&lt;BR /&gt;# generic check function&lt;BR /&gt;&lt;BR /&gt;CODE=0&lt;BR /&gt;&lt;BR /&gt;check () {&lt;BR /&gt;&lt;BR /&gt;if [[ $? -ne 0 ]] ; then&lt;BR /&gt;&lt;BR /&gt;logfile "Unix Alert: Error Processing sftp01 MRD files, please investigate"&lt;BR /&gt;mail -s "$DATE:$TIME:$PROGPATH/$PROGNAME has failed, please investigate" chris@mail &amp;lt;$LOGFILE&lt;BR /&gt;rm $LCKFILE&lt;BR /&gt;&lt;BR /&gt;CODE=1&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;exit $CODE&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Yang</description>
      <pubDate>Tue, 31 Oct 2006 06:48:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011401#M99200</guid>
      <dc:creator>Yang Qin_1</dc:creator>
      <dc:date>2006-10-31T06:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011402#M99201</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Your code should perform as you want if you call the 'check' function immediately after a command that you want to evaulate for success.  If you need to do several commands, but check only the status of the first command later in your code, you would need to do something like:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;check () {&lt;BR /&gt;if [[ $1 -ne 0 ]] ; then&lt;BR /&gt;    echo "non-zero; exiting..."&lt;BR /&gt;    exit 1&lt;BR /&gt;fi&lt;BR /&gt;}&lt;BR /&gt;cp #...produces a non-zero return...&lt;BR /&gt;X=$?&lt;BR /&gt;date&lt;BR /&gt;check ${X}&lt;BR /&gt;echo "oops!"&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;...Are you sure that your code meets this requirement?&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 31 Oct 2006 06:51:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011402#M99201</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-10-31T06:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011403#M99202</link>
      <description>here is an example of my code:&lt;BR /&gt;&lt;BR /&gt;set_env&lt;BR /&gt;&lt;BR /&gt;check () {&lt;BR /&gt;&lt;BR /&gt;if [[ $? -ne 0 ]] ; then&lt;BR /&gt;&lt;BR /&gt;logfile "Unix Alert: Error Processing sftp01 MRD files, please investigate"&lt;BR /&gt;mail -s "$DATE:$TIME:$PROGPATH/$PROGNAME has failed, please investigate" chris@mail &amp;lt;$LOGFILE&lt;BR /&gt;rm $LCKFILE&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;logfile () {&lt;BR /&gt;&lt;BR /&gt;        MSG_STRING="$*"&lt;BR /&gt;        echo "$DATE:$TIME: $MSG_STRING" &amp;gt;&amp;gt; $LOGFILE&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ftp code .......... &amp;gt;&amp;gt; ftp script&lt;BR /&gt;&lt;BR /&gt;./ftpscript&lt;BR /&gt;check&lt;BR /&gt;&lt;BR /&gt;ftp code .......... &amp;gt;&amp;gt; ftp script2&lt;BR /&gt;&lt;BR /&gt;./ftpscript2&lt;BR /&gt;check&lt;BR /&gt;&lt;BR /&gt;ftp code ........... &amp;gt;&amp;gt; ftp script3&lt;BR /&gt;&lt;BR /&gt;./ftpscript3&lt;BR /&gt;check&lt;BR /&gt;&lt;BR /&gt;logfile " Finished processing ftp "&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If the script encounters any error's then I want it to exit here however I have noticed ftp1 failing then the check mails abd the script will then continue.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 31 Oct 2006 07:07:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011403#M99202</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2006-10-31T07:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011404#M99203</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;How does your FTP script determine the success for failure of the FTP it does?&lt;BR /&gt;&lt;BR /&gt;If you are relying on a non-zero return value from an FTP to denote a failed FTP, then that is a problem.&lt;BR /&gt;&lt;BR /&gt;Your FTP script needs to examine the result of its transfer in the reply it returns.  As documented in the 'ftpd(1M)' manpages, this is a three-digit code.  For example, a value of 226 might indicate a successful transfer.  You need to capture this dialog; examine it; and construct your own zero (0) or one (1) exit status from your FTP script.  In that fashinon, your 'check' function will work as expected.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 31 Oct 2006 08:06:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011404#M99203</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-10-31T08:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011405#M99204</link>
      <description>set_env&lt;BR /&gt;&lt;BR /&gt;RET=0&lt;BR /&gt;&lt;BR /&gt;check () {&lt;BR /&gt;&lt;BR /&gt;if [[ $? -ne 0 ]] ; then&lt;BR /&gt;&lt;BR /&gt;logfile "Unix Alert: Error Processing sftp01 MRD files, please investigate"&lt;BR /&gt;mail -s "$DATE:$TIME:$PROGPATH/$PROGNAME has failed, please investigate" chris@mail &amp;lt;$LOGFILE&lt;BR /&gt;rm $LCKFILE&lt;BR /&gt;&lt;BR /&gt;RET=1&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;logfile () {&lt;BR /&gt;&lt;BR /&gt;MSG_STRING="$*"&lt;BR /&gt;echo "$DATE:$TIME: $MSG_STRING" &amp;gt;&amp;gt; $LOGFILE&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ftp code .......... &amp;gt;&amp;gt; ftp script&lt;BR /&gt;&lt;BR /&gt;./ftpscript&lt;BR /&gt;check&lt;BR /&gt;&lt;BR /&gt;if [ $RET -ne 0 ] ; then&lt;BR /&gt;   exit 1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;ftp code .......... &amp;gt;&amp;gt; ftp script2&lt;BR /&gt;&lt;BR /&gt;./ftpscript2&lt;BR /&gt;check&lt;BR /&gt;&lt;BR /&gt;if [ $RET -ne 0 ] ; then&lt;BR /&gt;   exit 1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;ftp code ........... &amp;gt;&amp;gt; ftp script3&lt;BR /&gt;&lt;BR /&gt;./ftpscript3&lt;BR /&gt;check&lt;BR /&gt;&lt;BR /&gt;if [ $RET -ne 0 ] ; then&lt;BR /&gt;   exit 1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;logfile " Finished processing ftp "&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Yang&lt;BR /&gt;</description>
      <pubDate>Tue, 31 Oct 2006 08:21:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011405#M99204</guid>
      <dc:creator>Yang Qin_1</dc:creator>
      <dc:date>2006-10-31T08:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011406#M99205</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;there's no need of global variables - set a return value for your check function:&lt;BR /&gt;&lt;BR /&gt;check () { [ $1 -eq 0 ] &amp;amp;&amp;amp; return 0&lt;BR /&gt;logfile ...&lt;BR /&gt;mail -s ...&lt;BR /&gt;rm ...&lt;BR /&gt;return $1&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;create-ftpscript &amp;gt;ftpscript1&lt;BR /&gt;&lt;BR /&gt;ftpscript1&lt;BR /&gt;if ! check $?&lt;BR /&gt;then exit $?   # this will be the ret.val of check()&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;mfG Peter&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 31 Oct 2006 10:26:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011406#M99205</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-10-31T10:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011407#M99206</link>
      <description>James,&lt;BR /&gt;&lt;BR /&gt;Thanks for your comments, I am not particulaly interested in the FTP'd file itself because if the file transfer is a failure then it will be picked up again elsewhere.&lt;BR /&gt;&lt;BR /&gt;I am looking for failures within the transfer process - ie if one ftp failed then the script must stop so when run next time the remaining files processed.&lt;BR /&gt;&lt;BR /&gt;I will attach the script as it is now.&lt;BR /&gt;&lt;BR /&gt;Pete,&lt;BR /&gt;&lt;BR /&gt;can you elaborate on your comments as I am not sure of the syntax here - as I can see yang has the solution?&lt;BR /&gt;&lt;BR /&gt;Thanks for your help - if you have any idea's then I will take them onboard.&lt;BR /&gt;&lt;BR /&gt;cheers</description>
      <pubDate>Tue, 31 Oct 2006 11:16:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011407#M99206</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2006-10-31T11:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011408#M99207</link>
      <description>Hi (again) Lawrenzo:&lt;BR /&gt;&lt;BR /&gt;As I suspected, you are assuming that a failed FTP transfer is going to be reflected in the exit status from the FTP.  It is *not*.&lt;BR /&gt;&lt;BR /&gt;Consider the guts of the FTP process handling:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;| ftp -in -v  &amp;gt;&amp;gt; ${FTPLOGF} 2&amp;gt;&amp;amp;1                                         &lt;BR /&gt;&lt;BR /&gt;RESULTS=`awk 'BEGIN{X=1};&lt;BR /&gt;        {if (tolower($0)~/^226 transfer complete/) {X=0}};&lt;BR /&gt;        {if (tolower($0)~/^226 transfer finished successfully/) {X=0}};&lt;BR /&gt;                END{print X}' ${FTPLOGF}`&lt;BR /&gt;&lt;BR /&gt;if [ "${RESULTS}" != 0 ]; then&lt;BR /&gt;  postalert "'${REQUEST}' failed"&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;This captures the verbose dialog of the FTP in ${FTPLOGF}; parses the dialog looking for an indication of a successful transfer; and sets an exit status based on the parsed text.&lt;BR /&gt;&lt;BR /&gt;Be advised that the actual message text from the FTP session may differ depending upon the software in use.  Thus, you may have to adjust the code.  The three-digit FTP reply is documented in the manpages for 'ftpd(1M)' as I previously noted.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 31 Oct 2006 11:49:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011408#M99207</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-10-31T11:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011409#M99208</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;the syntax is exactly as written, you have to add your real strings after the '...' only.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;check () { [ $1 -eq 0 ] &amp;amp;&amp;amp; return 0&lt;BR /&gt;logfile ...&lt;BR /&gt;mail -s ...&lt;BR /&gt;rm ...&lt;BR /&gt;return $1&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;# here are your script generator command(s)&lt;BR /&gt;create-ftpscript &amp;gt;./ftpscript1&lt;BR /&gt;&lt;BR /&gt;./ftpscript1&lt;BR /&gt;# this is plain ksh/posix-Shell syntax:&lt;BR /&gt;if ! check $?&lt;BR /&gt;then exit $? # this will be the ret.val of check()&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;# add your additional code here&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;mfG Peter&lt;BR /&gt;</description>
      <pubDate>Tue, 31 Oct 2006 12:00:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011409#M99208</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-10-31T12:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: exit my scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011410#M99209</link>
      <description>thanks everone for your help ....&lt;BR /&gt;&lt;BR /&gt;James and Peter solutions worked best however all idea's have been appreciated.&lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Wed, 01 Nov 2006 06:26:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/exit-my-scripts/m-p/5011410#M99209</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2006-11-01T06:26:18Z</dc:date>
    </item>
  </channel>
</rss>

