【发布时间】:2020-12-11 21:13:18
【问题描述】:
我在为实例组运行虚拟机启动脚本时遇到问题。找不到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。PATH是用于查找所有命令的基本变量。将代码中的所有引用替换为$myHomePath或类似名称,您将更接近工作系统。当您执行echo $PATH时,您希望看到类似/usr/local/bin/:/usr/bin/:/bin:/usr/sbin的内容。祝你好运。
标签: bash ubuntu google-cloud-platform google-compute-engine