Shell - PLSQL multiple process problem.

I have a Shell Script which runs a PLSQL stored proc. Here is the summary:

  • create LOCK file
  • check if LOCK exist, if exists, abort.
  • run Stored Proc and insert/update DB
  • remove LOCK file

The problem is in random cases, some records are inserted 2x (with exactly the same data,date etc.). I suspect there are 2 processes that ran at the same time.

The script is ran using cron.

Thanks

I forgot to add:

In the Stored Proc, if there is an existing record, update the record. This will prevent multiple record.