I'm not sure there's any one-line robust solution,
so you might end up rolling your own.
Lockfiles are imperfect, but less so than using 'ps | grep | grep -v' pipelines.
Having said that, you might consider keeping the process control
separate from your script - have a start script.
Or, at least factor it out to functions held in a separate file,
so you might in the caller script have:
. my_script_control.ksh
# Function exits if cannot start due to lockfile or prior running instance.
my_start_me_up lockfile_name;
trap "rm -f $lockfile_name; exit" 0 2 3 15
in each script that needs the control logic.
The trap ensures that the lockfile gets removed when the caller exits,
so you don't have to code this on each exit point in the script.
Using a separate control script means that you can sanity check for edge cases:
remove stale log files, verify that the lockfile is associated correctly with
a currently running instance of the script, give an option to kill the running process, and so on.
It also means you've got a better chance of using grep on ps
output successfully.
A ps-grep can be used to verify that a lockfile has a running process associated with it.
Perhaps you could name your lockfiles in some way to include information about the process:
user, pid, etc., which can be used by a later script invocation to decide whether the process
that created the lockfile is still around.