I want to know from within the script if that script already running.
A regular look on ps won't cut it as it get's different arguments in different order..
So the function should do:
check_already_running(){
if [ `ps -ef| grep $script_name_with_arguments | wc -l ` -gt 1 ]
then
echo "already running"
exit 1
else
echo "ok"
fi
}
For example let's assume I ran ./test.sh -a 2 -c 4, so:
server:/tmp >./test.sh
ok
server:/tmp >./test.sh -a
ok
server:/tmp >./test.sh -a 2 -c 4
already running
server:/tmp >./test.sh -a 2 -c 4
already running
server:/tmp >./test.sh -c 4 -a 2
already running
I'm guessing the last 2 examples makes it a lot harder and longer to check, so if you can provide 2 options - one that's enough for exact command running and the other one if the user sent the same arguments but with different order/extra spacing.