在任何其他 linux 发行版上,我可以使用 shebang 创建一个文件并运行 shell 脚本,如下所示:
$ chmod +x test.sh
$ ./test.sh Johnny
hello Johnny
但是在 Google Cloud Platform Container-Optimized OS 上,我得到
-bash: ./test.sh: Permission denied
如果我以
sh
为前缀例如sh test.sh Johnny
它会起作用。我怎样才能让它正常工作?$ cat test.sh
#!/usr/bin/env sh
echo "Hello $@"
matt@rancher-4mmm /tmp/matt $ chmod +x test.sh
matt@rancher-4mmm /tmp/matt $ sh ./test.sh matt
Hello matt
matt@rancher-4mmm /tmp/matt $ ./test.sh matt
-bash: ./test.sh: Permission denied
matt@rancher-4mmm /tmp/matt $ ls -la
total 4
drwxr-xr-x 2 matt matt 60 Feb 28 20:00 .
drwxrwxrwt 14 root root 280 Feb 28 19:59 ..
-rwxr-xr-x 1 matt matt 35 Feb 28 20:00 test.sh
最佳答案
COS 节点上的大多数文件系统都挂载了“noexec”标志,因此您无法从它们执行二进制文件。
一些解决方法:
关于google-cloud-platform - 无法在 Google Container-Optimized OS 上运行可执行的 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49037720/