Skip to content
Advertisement

Can`t call command with variable on sh file using ssh

I have the script on centos 7 server for kill process by used id:

#!/bin/sh

echo "killing services..."

kill -9 "$(lsof -t -i:3011)"
kill -9 "$(lsof -t -i:4011)"

Above script works fine when it is called from the server.

But my goal calls this file using ssh from my local machine like:

ssh xxx@xxx.x "sh ~/stopServices.sh"

But I git this error:

killing services...
/home/system/gepick-dev/stopDevServices.sh: line 5: lsof: command not found
/home/system/gepick-dev/stopDevServices.sh: line 5: kill: `': not a pid or valid job spec
/home/system/gepick-dev/stopDevServices.sh: line 6: lsof: command not found
/home/system/gepick-dev/stopDevServices.sh: line 6: kill: `': not a pid or valid job spec

Advertisement

Answer

you need to install lsof on the remote server.

or try to add the full path like /usr/sbin/lsof to your script or configure your PATH in the remote server if the binary is already installed

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement