0

In a korn shell script, I am running expdp. I have made the script to where it can be reusable so if a later process fails, I can run it again without running the already completed steps. I am running two processes in the background and waiting for both to complete before moving ahead in the script. For example, I am using the below logic to wait. After the expdp process completes, I am using a log function to write a completed message.

while   ps | grep "expdp" | grep -v grep
do
    echo expdp is still in the ps output. Must still be running.
    sleep 5
done

WriteLog "Completed exporting client schemas"

If the process does not exists (i.e. reusing the script after fixing any errors which occurred after expdp), how do I set it up to where the writelog occurs only when the expdp process exists. If no process is found from ps then it should not write log again.

2
  • 1
    You should avoid that ps | grep expdp | grep -v grep usage: unix.stackexchange.com/questions/3340/… There's a race condition in that pipeline that will sometimes cause it to act as if expdp process is not running. It's an ugly, ugly race, and it doesn't occur very often. Usually after working hours.
    – user732
    Apr 30, 2015 at 18:40
  • 1
    I am taking the liberty of assuming by expdp command you are referring to Oracle database export datapump. If yes, since Oracle 10g the absence of expdp process does not mean the datapump is not running. expdp process can terminate but the job will run asynchronously within the database. You can initiate expdp , issue ctrl-c and the job will be still running.
    – jsampath
    Apr 30, 2015 at 20:42

1 Answer 1

0

I think you're seaching in a wrong way. I'd write such a script like this:

if [ "z$STEP5" != "zOK" ] ; then
    expdp -your_options > $logfile &
    while ps ax | grep [e]xpdp ; do
        echo "expdp still in progress..."
        sleep 5
    done
    wait # in order to be sure there is no more background processes...
    tail -n1 $logfile | grep "successfully without warnings" >/dev/null 2>&1
    if [ $? -ne 0 ] ; then 
        echo "Some errors occured while export"
    else
        echo "Export done sucessfully"
    fi
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .