Using heredoc to execute multi-line commands on a remote machine.
Trying to get pid of a server to kill that server located in the remote machine
#!/bin/bash
HOST_IP="10.180.5.23"
read -p "For HOST RESTART press 1" num
if [ "$num" == "1" ]
then
ssh -t -t $HOST_IP << 'EOSSH'
line=$(pgrep -f host_server1)
echo $line
arr=($line)
sudo kill -9 "${arr[1]}"
EOSSH
fi
Error : kill: (15015) - Operation not permitted
kill "$line". You should probably not be usingkill -9, either.