Search code examples
shellcentos7killkill-process

SHELL automatically kill process from crontab


I have several java processes but only those problematic I would like to kill periodically on every 2 minutes on Centos7.

I would like to kill process PIDs which are run over this command.

/var/tmp/java -c /var/tmp/w.conf

If I try kill using the process ID process is killed automatically.

If I try to run this:

kill $(ps aux | grep 'java -c '| awk '{print $2}')

I am getting result:

-bash: kill: (129253) - No such process

how I should define script and crontab to kill automatically those processes?


Solution

  • Use

    pkill -f '/var/tmp/java -c /var/tmp/w.conf'