0

I have a shell script scheduled with a cronjob in my linux machine. The script has a kubectl command which sets the context and scaleup services based on a previous version file.

kubectl config set-context <AWSClusterARN> --namespace=<name>
kubectl get deploy --no-headers -n name | grep '^svc1\|^svc2' | awk '{print $1, $4}' > deploy_state_before_scale.txt

I have the output of the shell directed to a log file. When I checked it today, it shows

/path/filename.sh: line 19: kubectl: command not found
/path/filename.sh: line 21: kubectl: command not found
/path/filename.sh: line 23: kubectl: command not found

But when I run the file manually as ./filename.sh, the commands get executed.

Context "<AWSClusterARN>" modified.
Scaling down svc1
deployment.apps/svc1 scaled
  • You obviously forgot to set the PATH correctly in your script. – user1934428 Mar 23 '22 at 08:33
  • I ran these commands on following https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH echo 'export PATH=$PATH:$HOME/bin' >> ~/.bash_profile And # echo $PATH /sbin:/bin:/usr/sbin:/usr/bin:/root/bin – Aadhinarayanan J Mar 23 '22 at 09:33
  • Don't put code into a comment. It is hard to read. Put it into your comment. Also your .bash_profile is irrelevant here. See the section _INVOCATION_ in the bash man page. Put the PATH definition into the script, which your are going to invoke. – user1934428 Mar 23 '22 at 10:35

0 Answers0