How to kill a process in shell script which is running through cron

I have a shell script which is running in cronjob. This shell script has start with killing the process if it is already running and start the new process again.

To do so I wrote the below line at the beginning of my shell script.

kill -9 $(ps -ef | grep soffice | grep -v grep | awk '{ print $2 }')