{"record":{"id":"bf30f9b459b0a26a","repo":"hashicorp/terraform","slug":"error-starting-script-v","errorCode":null,"errorMessage":"Error starting script: %v","messagePattern":"Error starting script: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/builtin/provisioners/remote-exec/resource_provisioner.go","lineNumber":279,"sourceCode":"\t\tdefer outW.Close()\n\t\tdefer errW.Close()\n\n\t\tgo copyUIOutput(o, outR)\n\t\tgo copyUIOutput(o, errR)\n\n\t\tremotePath := comm.ScriptPath()\n\n\t\tif err := comm.UploadScript(remotePath, script); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to upload script: %v\", err)\n\t\t}\n\n\t\tcmd = &remote.Cmd{\n\t\t\tCommand: remotePath,\n\t\t\tStdout:  outW,\n\t\t\tStderr:  errW,\n\t\t}\n\t\tif err := comm.Start(cmd); err != nil {\n\t\t\treturn fmt.Errorf(\"Error starting script: %v\", err)\n\t\t}\n\n\t\tif err := cmd.Wait(); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// Upload a blank follow up file in the same path to prevent residual\n\t\t// script contents from remaining on remote machine\n\t\tempty := bytes.NewReader([]byte(\"\"))\n\t\tif err := comm.Upload(remotePath, empty); err != nil {\n\t\t\t// This feature is best-effort.\n\t\t\tlog.Printf(\"[WARN] Failed to upload empty follow up script: %v\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/builtin/provisioners/remote-exec/resource_provisioner.go#L261-L297","documentation":"The remote-exec provisioner's runScripts function wraps comm.Start failures with 'Error starting script: %v'. After successfully uploading the script to the remote machine, it constructs a remote.Cmd and calls comm.Start to execute it. If the remote command cannot be started (e.g., the script path is invalid, the shell is unavailable, or the SSH session has an execution error), this error is returned.","triggerScenarios":"Calling comm.Start(cmd) at resource_provisioner.go:278 after a successful script upload. The communicator fails to start the remote command. Causes include the remote shell not being available, the script file having been removed between upload and execution, or the SSH channel for command execution failing to open.","commonSituations":"The remote machine's default shell is misconfigured or unavailable. The uploaded script path (from comm.ScriptPath) is on a read-only filesystem or was cleaned up by a security agent. The SSH session's exec channel is restricted by the remote sshd configuration. The script lacks execute permissions on the remote.","solutions":["Ensure the remote machine has a working default shell (e.g., /bin/bash).","Verify the SSH user has permission to execute commands via the exec channel.","Check that any security software on the remote is not quarantining or removing uploaded scripts.","Use the 'inline' attribute instead of 'script'/'scripts' to avoid file-based execution if the remote filesystem is problematic."],"exampleFix":"# before — script upload + exec may fail on restricted remotes\nprovisioner \"remote-exec\" {\n  script = \"${path.module}/deploy.sh\"\n}\n\n# after — use inline to avoid file-based execution issues\nprovisioner \"remote-exec\" {\n  inline = [\n    \"#!/bin/bash\",\n    \"set -e\",\n    \"echo 'deploying...'\",\n    \"# your commands here\"\n  ]\n}","handlingStrategy":"retry","validationCode":"// Verify the remote shell is available before starting\n// (check via a simple echo command in a pre-flight remote-exec)\n// Ensure ScriptPath returns a path on a writable, executable filesystem","typeGuard":null,"tryCatchPattern":"// Retry command start\nfor i := 0; i < 3; i++ {\n    err := comm.Start(cmd)\n    if err == nil {\n        break\n    }\n    if i == 2 {\n        return fmt.Errorf(\"Error starting script after retries: %v\", err)\n    }\n    time.Sleep(time.Duration(i+1) * time.Second)\n}","preventionTips":["Ensure the remote machine has a functional default shell (/bin/bash or /bin/sh).","Verify the SSH user has exec channel permissions in the remote sshd_config.","Use 'inline' commands instead of uploaded scripts if the remote filesystem is restrictive.","Check that security software is not removing uploaded scripts before execution."],"tags":["terraform","remote-exec","provisioner","ssh","execution","go"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}