Like most Linux programs which access sensitive data, making tons of changes all at once can be dangerous. But the way they all get along is by creating lock files. Little files whose mere existence causes all other processes to look the other way.
What you do is when the script starts, it makes, or 'touch'es a file so that it exists. But it only does so if the file doesn't already exist. If the file was previously there, the script exits (preferrably with an error code like 'Lock file detected; script aborting'). Then the script proceeds to make its changes, and then when done, it deletes the lock file, thereby allowing another process to take over.
The cool thing is that if you want, you could put diagnostic information into the lock file, like time of creation, what IP originated the script, etc. So that way, if the script fails and the lock file is never deleted you'll have information to track down what caused the problem.
Hope this helps.