GCP Instance Startup Script Error – How to Resolve

google-cloud-platformshell-scripting

Trying to add a startup script following the sample here: https://cloud.google.com/compute/docs/startupscript

The instance is created with no problems but the script does not execute. Console shows the following output:

Jul 28 15:54:39 testclient-pbx startup-script: INFO Starting startup scripts.

Jul 28 15:54:39 testclient-pbx startup-script: INFO Found startup-script in metadata.

Jul 28 15:54:39 hostname startup-script: INFO startup-script: /bin/bash: /startup-aVpN6i/tmpVVdFyB: /bin/bash^M: bad interpreter: No such file or directory

Jul 28 15:54:39 hostname startup-script: INFO startup-script: Return code 126.

Jul 28 15:54:39 hostname startup-script: INFO Finished running startup scripts.

I'm actually trying to run more complex script but was receiving same error. Using debian-cloud/debian-9 image.

Best Answer

I'm using VScode on Win platform and as you can see above the message hinted file was not found. I had to change CRLF in VScode to LF "Unix" style and script now runs correctly! In VScode just click the CRLF bottom right and change to LF.

image