- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Restart a function if it gets aborted during the e...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2007 12:01 AM
09-11-2007 12:01 AM
I have a shell script which runs pl/sql procedures sequentially.
For example,
The fist procedure connects to database and extract a record from the database,
Second procedure does an update to database viz. removes a row from the same database.
And during the third procedure execution, if it get aborted (because of some reasons), the script will call exit 1.
Now my concern is if I rerun the script, it will run the whole script once again. I
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.
Solved! Go to Solution.
- Tags:
- SQL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2007 12:05 AM
09-11-2007 12:05 AM
SolutionYou 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.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2007 02:41 AM
09-11-2007 02:41 AM
Re: Restart a function if it gets aborted during the excution of script
Thanks much for the pointer.
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.
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.
Many Thanks,
Regards,
Raghu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2007 02:51 AM
09-11-2007 02:51 AM
Re: Restart a function if it gets aborted during the excution of script
> 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.
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.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2007 02:58 AM
09-11-2007 02:58 AM
Re: Restart a function if it gets aborted during the excution of script
Your script should look something like this:
typeset -i LAST_TASK=0
typeset LOCKFILE=mylock
if [[ -r "${LOCKFILE} ]]
then # file exists
LAST_TASK=$(tail -1 "${LOCKFILE}")
fi
rm -f "${LOCKFILE}"
if [[ ${LAST_TASK} -lt 1 ]]
then
# Do step 1
echo "1" >> "${LOCKFILE}"
fi
if [[ ${LAST_TASK} -lt 2 ]]
then
# Do Step 2
echo "2" >> "${LOCKFILE}"
fi
and so on until the end; if it reaches that point rm ${LOCKFILE}.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2007 02:58 AM
09-11-2007 02:58 AM
Re: Restart a function if it gets aborted during the excution of script
Thanks much. I will try the same.
Regards,
Raghu.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2007 03:03 AM
09-11-2007 03:03 AM
Re: Restart a function if it gets aborted during the excution of script
Thanks for sharing the code.
I will work on the same.
Regards,
Raghu.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2007 07:27 PM
10-20-2007 07:27 PM
Re: Restart a function if it gets aborted during the excution of script
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.
Now I have one more requirement, suppose if a step number passed as an argument, only that step should get execute.
In concise, here is a brief about the requirement.
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.
2. If a step no/nos (single/multiple) are given as an argument, it should execute only those steps, and not the entire program.
I request you to kindly suggest a pointer for the same. Your inputs are highly appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2007 01:34 AM
10-21-2007 01:34 AM
Re: Restart a function if it gets aborted during the excution of script
I'd appreciate some credit for my first suggestion, too.
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.
# cat ./parse
#!/usr/bin/sh
if [ $# -eq 0 ]; then
STEP=0
echo "no arguments; use file"
else
while (( $# > 0 ))
do
STEP=$1
shift
if [ `expr "${STEP}" : '[0-9]*'` -ne `expr "${STEP}" : '.*'` ]; then
echo "ERROR: STEP must be a number; scanning: ${STEP}"
exit 1
fi
echo "STEP-${STEP} requested"
done
fi
...Thus:
# ./parse 3 5 7
STEP-3 requested
STEP-5 requested
STEP-7 requested
# ./parse 2
STEP-2 requested
# ./parse
no arguments; use file
# ./parse 2 and 4a
STEP-2 requested
ERROR: STEP must be a number; scanning: 4a
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2007 01:52 AM
10-21-2007 01:52 AM
Re: Restart a function if it gets aborted during the excution of script
Sorry, it was omitted by an oversight. I have assigned the points now.
I will work on the same.
Regards,
Raghu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2007 05:35 AM
10-21-2007 05:35 AM
Re: Restart a function if it gets aborted during the excution of script
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.
The following modification might be useful to you.
# cat ./parse
#!/usr/bin/sh
typeset -i MAX=$#-1
typeset -i N=0
if [ $# -eq 0 ]; then
STEP=0
echo "no arguments; use file"
else
set -A STEPS $@
while (( $# > 0 ))
do
STEP=$1
shift
if [ `expr "${STEP}" : '[0-9]*'` -ne `expr "${STEP}" : '.*'` ]; then
echo "ERROR: STEP must be a number; scanning: ${STEP}"
exit 1
fi
echo "STEP-${STEP} requested"
done
fi
N=0
while (( N <= MAX ))
do
echo "now processing STEP-${STEPS[$N]}"
let N=N+1
done
exit 0
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.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2007 08:19 AM
10-21-2007 08:19 AM
Re: Restart a function if it gets aborted during the excution of script
If you want perfection on saving and restoring, you should quote the parms:
set -A STEPS "$@"
- Tags:
- set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2007 09:49 AM
10-21-2007 09:49 AM
Re: Restart a function if it gets aborted during the excution of script
Dennis>: If you want perfection on saving and restoring, you should quote the parms:
set -A STEPS "$@"
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.
Regards!
...JRF...