I cant stop the process, so I have manually kill process using kill command as root user, so from the output service splunk status, I get all the pid, I need a script to filter all those pid's, and run kill command on those process id. After that I will change the user permission on the respective directory.
I am trying to remotely execute this command to kill process ID, these is error messages I am getthing, any idea what I am missing here.
When I login to host I can run this command successfully, but not remotely.
$ ssh -t 10.12.9.28 'sudo kill -9 `/sbin/service splunk status | awk -F ": |)" '/PID/ {print $(NF-1) }'`'
-bash: NF-1: command not found
awk: cmd. line:1: fatal: cannot open file `{print' for reading (No such file or directory)
splunk: unrecognized service
usage: kill [ -s signal | -p ] [ -a ] pid ...
kill -l [ signal ]
Connection to 10.12.9.28 closed.
$
You both seem to be having issues figuring out how to handle shell quoting.
To pass a single-quote when using a single-quoted string, you need to close the string, escape the single-quote, then re-open the string. In short, for each ' you need to pass, use '\'' .
Example: echo '>>'\''<<' prints >>'<< .
For the double-quoted equivlalent, simply backslash-escape the double-quote within the double-quoted string.
Finally, don't use `...` ; it's an obsolete, deprecated, and troublesome form of command substitution. Instead, use $(...) .