Home > Others > How to kill a process in a shell script that is running through cron

How to kill a process in a shell script that 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.

First step is to find the PID (Process Id) and once that is found use the kill -9 command to terminate the running process without knowing the PID.

ps -ef | grep soffice | grep -v grep | awk '{ print $2 }'

Final command –

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