라는 파일이 있습니다테스트 파일디렉토리에 있습니다/홈/사용자다음 코드를 사용하세요.
#!/bin/bash
echo "Execute command number 1 (bash)"
. /opt/IBM/taddm/dist/bin/control.sh
echo "Execute command number 2 (jython)"
. /opt/IBM/taddm/dist/bin/collect_logs.jy "@g"
명령 1을 실행하면 다음 메시지가 나타납니다.
./test.sh: line 5: /opt/IBM/taddm/dist/bin/control.sh: No such file or directory
대상(/bin)으로 이동하여 거기에서 명령을 실행하면 문제가 없습니다.
명령 2를 실행하면 다음 메시지가 나타납니다.
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 1: Script: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 2: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 2: $'user@XXXXX:~\a\E[?1034h[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 3: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 3: user@XXXXX:/opt/IBM/taddm/dist/log/support[user@XXXXX: No such file or directory
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 4: total: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 5: -rw-r-----.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 5: $'31mTADDM_ISA_Collection.General.20220323140619.zip\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 6: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 6: user@XXXXX:/opt/IBM/taddm/dist/log/support[user@XXXXX: No such file or directory
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 7: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 7: user@XXXXX:/opt/IBM/taddm/dist/log/support[user@XXXXX: No such file or directory
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 8: total: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 9: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 9: user@XXXXX:/opt/IBM/taddm/dist/log/support[user@XXXXX: No such file or directory
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 10: $'\E[3': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 10: $'J\E[H\E[2J\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 10: user@XXXXX:/opt/IBM/taddm/dist/log/support[user@XXXXX: No such file or directory
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 11: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 11: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 12: total: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 13: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 13: $'34m12:35:27\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 14: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 14: $'34m2022\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 15: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 15: $'34m22\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 16: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 16: $'34mCET\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 17: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 17: $'34mMar\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 18: -rwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 18: $'32mmenu.sh\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 19: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 19: $'34mPM\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 20: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 20: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 21: $'\E[3': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 21: $'J\E[H\E[2J\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 21: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 22: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 22: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 23: total: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 24: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 24: $'34m12:35:27\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 25: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 25: $'34m2022\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 26: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 26: $'34m22\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 27: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 27: $'34mCET\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 28: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 28: $'34mMar\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 29: -rwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 29: $'32mmenu.sh\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 30: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 30: $'34mPM\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 31: -rw-rw-r--.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 32: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 32: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 33: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 33: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 34: total: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 35: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 35: $'34m12:35:27\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 36: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 36: $'34m2022\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 37: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 37: $'34m22\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 38: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 38: $'34mCET\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 39: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 39: $'34mMar\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 40: -rwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 40: $'32mmenu.sh\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 41: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 41: $'34mPM\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 42: -rwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 42: $'32mtest.sh\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 43: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 43: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 44: $'\E[3': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 44: $'J\E[H\E[2J\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 44: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 46: $'\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 51: syntax error near unexpected token `$'do\r''
'opt/IBM/taddm/dist/bin/collect_logs.jy: line 51: `do
대상(/bin)으로 이동하여 거기에서 명령을 실행하면 문제가 없습니다.
source
또한 파일 확장자(/bin/control 및 /bin/collect_logs) 없이 명령을 시도하고 대신 사용해 보았지만 .
역시 도움이 되지 않았습니다.
내 bash 스크립트 내에서 다른 스크립트를 실행할 수 없는 이유는 무엇입니까?
감사해요
답변1
스크립트가 $PATH에 있고 실행 가능하다면 다음을
control.sh
입력하여 어디에서나 실행할 수 있다는 의미입니다.collect_logs.jy "@g"
당신은 이것을 할 수 있습니다
#!/bin/bash
echo "Execute command number 1 (bash)"
control.sh
echo "Execute command number 2 (jython)"
collect_logs.jy "@g"
디렉터리를 지정해야 하는 경우 점을 생략하면 됩니다.
#!/bin/bash
echo "Execute command number 1 (bash)"
/opt/IBM/taddm/dist/bin/control.sh
echo "Execute command number 2 (jython)"
/opt/IBM/taddm/dist/bin/collect_logs.jy "@g"
먼저 실행 가능하게 만들어야 할 수도 있습니다.
chmod +x /opt/IBM/taddm/dist/bin/control.sh
chmod +x /opt/IBM/taddm/dist/bin/collect_logs.jy