<?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: Restart a function if it gets aborted during the excution of script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068637#M92185</link>
    <description>Have your lock file record (one per line) a series of increasing numbers (starting at 1) as each step is completed. If the script finishes completely then rm the file.&lt;BR /&gt;&lt;BR /&gt;Your script should look something like this:&lt;BR /&gt;&lt;BR /&gt;typeset -i LAST_TASK=0&lt;BR /&gt;typeset LOCKFILE=mylock&lt;BR /&gt;&lt;BR /&gt;if [[ -r "${LOCKFILE} ]]&lt;BR /&gt;then # file exists&lt;BR /&gt;  LAST_TASK=$(tail -1 "${LOCKFILE}")&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;rm -f "${LOCKFILE}"&lt;BR /&gt;&lt;BR /&gt;if [[ ${LAST_TASK} -lt 1 ]]&lt;BR /&gt;  then&lt;BR /&gt;    # Do step 1&lt;BR /&gt;    echo "1" &amp;gt;&amp;gt; "${LOCKFILE}"&lt;BR /&gt;  fi&lt;BR /&gt; &lt;BR /&gt;if [[ ${LAST_TASK} -lt 2 ]]&lt;BR /&gt;  then&lt;BR /&gt;    # Do Step 2&lt;BR /&gt;    echo "2" &amp;gt;&amp;gt; "${LOCKFILE}"&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;and so on until the end; if it reaches that point rm ${LOCKFILE}.&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;</description>
    <pubDate>Tue, 11 Sep 2007 09:58:27 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2007-09-11T09:58:27Z</dc:date>
    <item>
      <title>Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068633#M92181</link>
      <description>Hello All,&lt;BR /&gt;&lt;BR /&gt;I have a shell script which runs  pl/sql procedures sequentially.   &lt;BR /&gt;For example,&lt;BR /&gt;The fist procedure connects to database and extract a record from the database,&lt;BR /&gt;Second procedure does an update to database viz. removes a row from the same database.&lt;BR /&gt;And during the third procedure execution, if it get aborted (because of some reasons), the script will call exit 1. &lt;BR /&gt;Now my concern is if I rerun the script, it will run the whole script once again. I&lt;BR /&gt;Please show some pointers to keep track the successfully executed functions so that when the script get executed next time it should only run the unsuccessful function which  got terminated last time.&lt;BR /&gt;</description>
      <pubDate>Tue, 11 Sep 2007 07:01:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068633#M92181</guid>
      <dc:creator>Raghu Chikkamenahalli</dc:creator>
      <dc:date>2007-09-11T07:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068634#M92182</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;You can write your own restart information (e.g. a last completed step number) to a file periodically.  Upon beginning execution you determine if the file exists and if so read the necessary restart data and begin at the appropriate step in the overall process.  Obviously, one you achieve a successful termination of your process, remove the file.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 11 Sep 2007 07:05:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068634#M92182</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-09-11T07:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068635#M92183</link>
      <description>Hi JRF&lt;BR /&gt;&lt;BR /&gt;Thanks much for the pointer.&lt;BR /&gt;&lt;BR /&gt;Based on your inputs,  I have put the controls to create a file ( which act like a lock) once the procedure exection is sucessful. Later at the end of the script I have incorporated a function to clean up all the lock files.&lt;BR /&gt;&lt;BR /&gt;But I am curious to know about how store the step information which you have mentioned. If possbile can show some light on the same.&lt;BR /&gt;&lt;BR /&gt;Many Thanks,&lt;BR /&gt;Regards,&lt;BR /&gt;Raghu&lt;BR /&gt;</description>
      <pubDate>Tue, 11 Sep 2007 09:41:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068635#M92183</guid>
      <dc:creator>Raghu Chikkamenahalli</dc:creator>
      <dc:date>2007-09-11T09:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068636#M92184</link>
      <description>Hi (again) Raghu:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; But I am curious to know about how store the step information which you have mentioned. If possbile can show some light on the same.&lt;BR /&gt;&lt;BR /&gt;This really depends on what information you need.  A simple integer step number might be all that you need to be able to restart at the appropriate point in your code.  You could write this into a file and read it upon restart if the file was present, or you could include the numeric value in the file name itself.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 11 Sep 2007 09:51:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068636#M92184</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-09-11T09:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068637#M92185</link>
      <description>Have your lock file record (one per line) a series of increasing numbers (starting at 1) as each step is completed. If the script finishes completely then rm the file.&lt;BR /&gt;&lt;BR /&gt;Your script should look something like this:&lt;BR /&gt;&lt;BR /&gt;typeset -i LAST_TASK=0&lt;BR /&gt;typeset LOCKFILE=mylock&lt;BR /&gt;&lt;BR /&gt;if [[ -r "${LOCKFILE} ]]&lt;BR /&gt;then # file exists&lt;BR /&gt;  LAST_TASK=$(tail -1 "${LOCKFILE}")&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;rm -f "${LOCKFILE}"&lt;BR /&gt;&lt;BR /&gt;if [[ ${LAST_TASK} -lt 1 ]]&lt;BR /&gt;  then&lt;BR /&gt;    # Do step 1&lt;BR /&gt;    echo "1" &amp;gt;&amp;gt; "${LOCKFILE}"&lt;BR /&gt;  fi&lt;BR /&gt; &lt;BR /&gt;if [[ ${LAST_TASK} -lt 2 ]]&lt;BR /&gt;  then&lt;BR /&gt;    # Do Step 2&lt;BR /&gt;    echo "2" &amp;gt;&amp;gt; "${LOCKFILE}"&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;and so on until the end; if it reaches that point rm ${LOCKFILE}.&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Tue, 11 Sep 2007 09:58:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068637#M92185</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-09-11T09:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068638#M92186</link>
      <description>Hi JRF,&lt;BR /&gt;&lt;BR /&gt;Thanks much. I will try the same.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Raghu.</description>
      <pubDate>Tue, 11 Sep 2007 09:58:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068638#M92186</guid>
      <dc:creator>Raghu Chikkamenahalli</dc:creator>
      <dc:date>2007-09-11T09:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068639#M92187</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Thanks for sharing the code.&lt;BR /&gt;&lt;BR /&gt;I will work on the same.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Raghu.</description>
      <pubDate>Tue, 11 Sep 2007 10:03:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068639#M92187</guid>
      <dc:creator>Raghu Chikkamenahalli</dc:creator>
      <dc:date>2007-09-11T10:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068640#M92188</link>
      <description>&lt;!--!*#--&gt;Hi Experts,&lt;BR /&gt;&lt;BR /&gt;Based on your guidelines, achieved restart capability of a function. Here I am logging each step with a step number (which is an integer) in to file permanently. If all the steps get executed successfully, file will be cleared. &lt;BR /&gt;&lt;BR /&gt;Now I have one more requirement, suppose if a step number passed as an argument, only that step should get execute. &lt;BR /&gt;&lt;BR /&gt;In concise, here is a brief about the requirement.&lt;BR /&gt;&lt;BR /&gt;1. If no arguments given, the script should check the step no exists in the restart file or not, if it exists, it should not get executed.&lt;BR /&gt;&lt;BR /&gt;2. If a step no/nos (single/multiple) are given as an argument, it should execute only those steps, and not the entire program.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I request you to kindly suggest a pointer for the same.  Your inputs are highly appreciated.&lt;BR /&gt;</description>
      <pubDate>Sun, 21 Oct 2007 02:27:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068640#M92188</guid>
      <dc:creator>Raghu Chikkamenahalli</dc:creator>
      <dc:date>2007-10-21T02:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068641#M92189</link>
      <description>&lt;!--!*#--&gt;Hi (again) Raghu:&lt;BR /&gt;&lt;BR /&gt;I'd appreciate some credit for my first suggestion, too.&lt;BR /&gt;&lt;BR /&gt;However, in answer to your latest question, this snippet of shell should enable you to get started.  Look at the 'sh-posix' manpages too.  The script below validates that any argument passed is a number.&lt;BR /&gt;&lt;BR /&gt;# cat ./parse&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;if [ $# -eq 0 ]; then&lt;BR /&gt;    STEP=0&lt;BR /&gt;    echo "no arguments; use file"&lt;BR /&gt;else&lt;BR /&gt;    while (( $# &amp;gt; 0 ))&lt;BR /&gt;    do&lt;BR /&gt;        STEP=$1&lt;BR /&gt;        shift&lt;BR /&gt;        if [ `expr "${STEP}" : '[0-9]*'` -ne `expr "${STEP}" : '.*'` ]; then&lt;BR /&gt;            echo "ERROR: STEP must be a number; scanning: ${STEP}"&lt;BR /&gt;            exit 1&lt;BR /&gt;        fi&lt;BR /&gt;        echo "STEP-${STEP} requested"&lt;BR /&gt;    done&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;...Thus:&lt;BR /&gt;&lt;BR /&gt;# ./parse 3 5 7&lt;BR /&gt;STEP-3 requested&lt;BR /&gt;STEP-5 requested&lt;BR /&gt;STEP-7 requested&lt;BR /&gt;&lt;BR /&gt;# ./parse 2&lt;BR /&gt;STEP-2 requested&lt;BR /&gt;&lt;BR /&gt;# ./parse&lt;BR /&gt;no arguments; use file&lt;BR /&gt;&lt;BR /&gt;# ./parse 2 and 4a&lt;BR /&gt;STEP-2 requested&lt;BR /&gt;ERROR: STEP must be a number; scanning: 4a&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Sun, 21 Oct 2007 08:34:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068641#M92189</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-10-21T08:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068642#M92190</link>
      <description>Hi JRF,&lt;BR /&gt;&lt;BR /&gt;Sorry, it was omitted by an oversight. I have assigned the points now. &lt;BR /&gt;&lt;BR /&gt;I will work on the same. &lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Raghu</description>
      <pubDate>Sun, 21 Oct 2007 08:52:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068642#M92190</guid>
      <dc:creator>Raghu Chikkamenahalli</dc:creator>
      <dc:date>2007-10-21T08:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068643#M92191</link>
      <description>&lt;!--!*#--&gt;Hi (again) Raghu:&lt;BR /&gt;&lt;BR /&gt;Since the code I presented is destructive to the argument list (the 'shift') we need to preserve the original argument list and then process it, in another pass, if its elements are valid.&lt;BR /&gt;&lt;BR /&gt;The following modification might be useful to you.&lt;BR /&gt;&lt;BR /&gt;# cat ./parse&lt;BR /&gt;#!/usr/bin/sh                                                                   &lt;BR /&gt;typeset -i MAX=$#-1                                                             &lt;BR /&gt;typeset -i N=0                                                                  &lt;BR /&gt;                                                                                &lt;BR /&gt;if [ $# -eq 0 ]; then                                                           &lt;BR /&gt;    STEP=0                                                                      &lt;BR /&gt;    echo "no arguments; use file"&lt;BR /&gt;else&lt;BR /&gt;    set -A STEPS $@&lt;BR /&gt;    while (( $# &amp;gt; 0 ))&lt;BR /&gt;    do&lt;BR /&gt;        STEP=$1&lt;BR /&gt;        shift&lt;BR /&gt;        if [ `expr "${STEP}" : '[0-9]*'` -ne `expr "${STEP}" : '.*'` ]; then&lt;BR /&gt;            echo "ERROR: STEP must be a number; scanning: ${STEP}"&lt;BR /&gt;            exit 1&lt;BR /&gt;        fi&lt;BR /&gt;        echo "STEP-${STEP} requested"&lt;BR /&gt;    done&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;N=0&lt;BR /&gt;while (( N &amp;lt;= MAX ))&lt;BR /&gt;do&lt;BR /&gt;    echo "now processing STEP-${STEPS[$N]}"&lt;BR /&gt;    let N=N+1&lt;BR /&gt;done&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;Note that the script's value of 'MAX' is established to be zero-relative, since elements of an array ('STEPS') are referenced with zero as the first element.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Sun, 21 Oct 2007 12:35:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068643#M92191</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-10-21T12:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068644#M92192</link>
      <description>&amp;gt;JRF: set -A STEPS $@&lt;BR /&gt;&lt;BR /&gt;If you want perfection on saving and restoring, you should quote the parms:&lt;BR /&gt;set -A STEPS "$@"&lt;BR /&gt;</description>
      <pubDate>Sun, 21 Oct 2007 15:19:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068644#M92192</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-10-21T15:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: Restart a function if it gets aborted during the excution of script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068645#M92193</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Dennis&amp;gt;: If you want perfection on saving and restoring, you should quote the parms:&lt;BR /&gt;set -A STEPS "$@"&lt;BR /&gt;&lt;BR /&gt;Agreed, although in the context I suggested the argument list, there would be no need to supply it in quotes like "4 5 6" 7 8 versus "4 5 6 7 8" versus 4 5 6 7 8 (without any quotes.  Your point is noted, though.  Thanks.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 21 Oct 2007 16:49:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/restart-a-function-if-it-gets-aborted-during-the-excution-of/m-p/4068645#M92193</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-10-21T16:49:57Z</dc:date>
    </item>
  </channel>
</rss>

