gpt4 book ai didi

bash - [Google Cloud][Compute Engine] 在启动脚本中找不到 Linux 基础命令

转载 作者:行者123 更新时间:2023-12-04 18:55:21 33 4
gpt4 key购买 nike

我在为实例组运行虚拟机启动脚本时遇到问题。像 touch 这样的命令, cat , chmod没有找到。

ubuntu@instance-template-****-1:~$ sudo google_metadata_script_runner -d --script-type startup
startup-script: INFO Starting startup scripts.
startup-script: INFO Found startup-script-url in metadata.
startup-script: INFO Downloading url from https://storage.googleapis.com/bucket-*****/startup-image to /home/ubuntu/startup-scripts/script using authentication token.
startup-script: INFO startup-script-url: /home/ubuntu
startup-script: INFO startup-script-url: /home/ubuntu
startup-script: INFO startup-script-url: /home/ubuntu/startup-scripts/script: line 11: touch: command not found
startup-script: INFO startup-script-url: /home/ubuntu/startup-scripts/script: line 12: touch: command not found
startup-script: INFO startup-script-url: /home/ubuntu/startup-scripts/script: line 13: touch: command not found
startup-script: INFO startup-script-url: /home/ubuntu/startup-scripts/script: line 15: chmod: command not found
startup-script: INFO startup-script-url: /home/ubuntu/startup-scripts/script: line 16: chmod: command not found
startup-script: INFO startup-script-url: /home/ubuntu/startup-scripts/script: line 71: ssh-keyscan: command not found
startup-script: INFO startup-script-url: /home/ubuntu/startup-scripts/script: line 72: ssh-keygen: command not found
startup-script: INFO startup-script-url: /home/ubuntu/startup-scripts/script: line 74: cat: command not found
startup-script: INFO startup-script-url: /home/ubuntu/startup-scripts/script: line 76: git: command not found
startup-script: INFO startup-script-url: /home/ubuntu/startup-scripts/script: line 78: sh: command not found
startup-script: INFO startup-script-url: Return code 127.
startup-script: INFO Finished running startup scripts.
脚本:
#!/bin/bash

PATH=/home/ubuntu

cd $PATH

touch $PATH/.ssh/id_rsa
touch $PATH/.ssh/id_rsa.pub
touch $PATH/.ssh/known_hosts

chmod 644 $PATH/.ssh/id_rsa.pub
chmod 600 $PATH/.ssh/id_rsa

echo $IDRSA > $PATH/.ssh/id_rsa
echo $IDRSA_PUB > $PATH/.ssh/id_rsa.pub

ssh-keyscan bitbucket.org >> bitbucketKey
ssh-keygen -lf bitbucketKey

cat bitbucketKey >> $PATH/.ssh/known_hosts

git clone git@bitbucket.org:repo/repo.git

sh ./repo/prepare

PROJECT_ID=$(curl "http://metadata.google.internal/computeMetadata/v1/project/numeric-project-id" -H "Metadata-Flavor: Google")

./repo/deploy/run --dev --project-id=$PROJECT_ID

最佳答案

当您设置 PATH=/home/ubuntu ,它会覆盖 PATH 的值您应该在 shell 中获取的环境变量,它会强制后续命令以 "command not found" 结尾错误,因为用于运行这些命令的相应可执行文件在新路径 /home/ubuntu 上不可用你刚刚设置的。您可以通过将该变量重命名为 PATH 以外的任何名称来解决此问题。以及它在您的脚本中出现的所有情况。您也可以使用小写的相同变量名称。 (如 path=home/ubuntu )。PATH环境变量是一个以冒号分隔的目录列表,当您输入命令时,您的 shell 会搜索这些目录。程序文件(可执行文件)保存在 Unix 系统上的许多不同位置。当您请求特定程序时,您的路径会告诉 Unix shell 在系统上的哪个位置查找。

关于bash - [Google Cloud][Compute Engine] 在启动脚本中找不到 Linux 基础命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63540547/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com