I need to implement a shell script that kills a process. The problem is that I need to do a conditional to be able to see if the process is running or not.
This is my code, but it is not working:
#!/bin/sh
if [ -x "MY_PROCCESS_NAME"]; then
killall MY_PROCCESS_NAME
else
echo "Doesn't exist"
fi
This is the error:
line 3: [: missing `]'
to check if a process is running on mac os x you can use:
if you want to reduce the number of shell scripts you can enclose one of the characters of the name of the process in square brackets:
combined in your test this would look like:
it’s a little more complicated than you would need to do under linux as you generally have the ‘pgrep’ command, which is the rough equivalent of the ‘ps -fe | grep … | grep -v grep’