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
    echo expdp is still in the ps output. Must still be running.
    sleep 5

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.

  • 1
    You should avoid that ps | grep expdp | grep -v grep usage:… 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. – Bruce Ediger Apr 30 '15 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 '15 at 20:42
up vote 0 down vote accepted

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
    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"
        echo "Export done sucessfully"

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.