Issue
I have a deploy script in which I want to clear the cache of my CDN. When I am on the server and run my script everything is fine, however when I SSH in and run only that file (i.e. not actually getting into the server, cd
ing into the directory and running it) it fails and states the my doctl
command cannot be found. This seems to only be an issue with this program over ssh, running systemctl --help works fine.
Please note that I have installed Digital Ocean's doctl
using sudo snap install doctl
and it is there.
Here is the .sh
file (minus comments):
#!/bin/sh
doctl compute cdn flush [MYID] --files [*] # static cache
So I am not sure what the issue is. Anybody have an idea?
Again, if I get into the server and run the file all works, but here is the SSH command I use that returns the error:
ssh [email protected] "/deploy/clear_digital_ocean_cache.sh"
And here is the error.
/deploy/clear_digital_ocean_cache.sh: 10: doctl: not found
Solution
Well one solution was to change the command to be an absolute path inside my .sh
file like so:
#!/bin/sh
/snap/bin/doctl compute cdn flush [MYID] --files [*] # static cache
I realized that I could run my user commands with ssh
(like systemctl
) so it was either change where doctl
was located (i.e. in the user bin) or ensure that the command was called with an absolute path adding the /snap/bin/
in front of the command.
Answered By - ViaTech