0

I am trying to run some scale up/down tests for kubernetes pods. I have written a following bash script

#!/bin/bash
# Use kubectl to update the number of replicas for the deployment
kubectl scale deployment 'deploymentname' --replicas=4 --namespace 'appns'

The script is being called from following main.js

import exec from 'k6/x/exec';

export default function () {
  // Call the shell script using the exec function
    let result  = exec.command('scale.sh');
}

Error

INFO[0000] 2023/05/13 00:10:59 exec: "scale.sh": executable file not found in $PATH on command: scale.sh

What am i missing?

jsingh13
  • 370
  • 1
  • 4
  • 12
  • 1
    Please paste your script at [shellcheck.net](http://www.shellcheck.net/) and try to implement the recommendations made there. – Cyrus May 13 '23 at 00:59
  • Except from removing 2 whitespaces, there is nothing wrong with the script. – jsingh13 May 13 '23 at 02:16
  • I suggest to use full path to your script `scale.sh` with `exec.command`. – Cyrus May 13 '23 at 02:43
  • What is the content of `PATH`, is the file in one of the directories in `PATH` and is the file actually executable? – knittl May 13 '23 at 06:07
  • @jsingh13 there's more wrong with the script than whitespace. Please do as [@Cyrus suggested](https://stackoverflow.com/questions/76240568/how-to-call-scripts-from-k6-tests#comment134448361_76240568) and also read [correct-bash-and-shell-script-variable-capitalization](https://stackoverflow.com/questions/673055/correct-bash-and-shell-script-variable-capitalization) and fix those issues too. Once you [edit] your question to show a script without those obvious issues then that rules out those as being your real problem and so people can then help you. – Ed Morton May 13 '23 at 14:19
  • @Cyrus even with the full path, I am still getting the error. – jsingh13 May 13 '23 at 17:52
  • Make it executable? `chmod u+x /path/to/scale.sh` – Cyrus May 13 '23 at 18:01
  • @Cyrus I did change it to an executable. `-rwxrwxrwx 1 root dialout 461 May 13 17:57 scale.sh` – jsingh13 May 13 '23 at 18:03
  • @knittl I updated the PATH variable to include the dir containing the script and the now I am getting no file or directory error. `INFO[0000] 2023/05/13 18:05:24 fork/exec /tests/scale.sh: no such file or directory on command: scale.sh` – jsingh13 May 13 '23 at 18:06
  • 1
    @EdMorton I have updated the script in question. – jsingh13 May 13 '23 at 18:07
  • Whatever you are hoping to accomplish, **`chmod 777` is *wrong* and *dangerous.*** You will want to revert to sane permissions ASAP (for your use case, probably `chmod 755`) and if you have had world writable system files on a public-facing system, at the very least investigate whether it could have been breached and used as a pivot point for breaking into your organization’s network. – tripleee May 13 '23 at 18:43

0 Answers0