{"record":{"id":"43f8f966b0ca6ff2","repo":"hashicorp/packer","slug":"error-removing-temporary-script-at-s-s","errorCode":null,"errorMessage":"Error removing temporary script at %s: %s","messagePattern":"Error removing temporary script at (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/shell/provisioner.go","lineNumber":404,"sourceCode":"\t\t}\n\t}\n\n\tif p.config.PauseAfter != 0 {\n\t\tui.Say(fmt.Sprintf(\"Pausing %s after this provisioner...\", p.config.PauseAfter))\n\t\ttime.Sleep(p.config.PauseAfter)\n\t}\n\n\treturn nil\n}\n\nfunc (p *Provisioner) cleanupRemoteFile(path string, comm packersdk.Communicator) error {\n\tctx := context.TODO()\n\terr := retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {\n\t\tcmd := &packersdk.RemoteCmd{\n\t\t\tCommand: fmt.Sprintf(\"rm -f %s\", path),\n\t\t}\n\t\tif err := comm.Start(ctx, cmd); err != nil {\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"Error removing temporary script at %s: %s\",\n\t\t\t\tpath, err)\n\t\t}\n\t\tcmd.Wait()\n\t\t// treat disconnects as retryable by returning an error\n\t\tif cmd.ExitStatus() == packersdk.CmdDisconnect {\n\t\t\treturn fmt.Errorf(\"Disconnect while removing temporary script.\")\n\t\t}\n\t\tif cmd.ExitStatus() != 0 {\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"Error removing temporary script at %s!\",\n\t\t\t\tpath)\n\t\t}\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\treturn err","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/shell/provisioner.go#L386-L422","documentation":"During cleanup the provisioner runs `rm -f <path>` on the remote host to delete the temporary uploaded script. If comm.Start fails to launch that command (connection error, shell unavailable), the error is wrapped as this message and returned from the retryable cleanup loop. Because `rm -f` is best-effort, this failure indicates a communicator-level problem, not a missing file.","triggerScenarios":"comm.Start(ctx, cmd) failing while running `rm -f <RemotePath>` in cleanupRemoteFile — dropped SSH/WinRM session, unreachable host after a reboot triggered by the script, or communicator channel error.","commonSituations":"Machine was rebooted by the script and is still coming up when cleanup runs; network flakiness at end of provisioning; sshd rate limiting; WinRM session limits.","solutions":["Ensure the machine is fully back up after any script-triggered reboot before provisioning ends (the built-in retry helps — give it time via start_retry_timeout)","Verify communicator connectivity (SSH/WinRM reachable, correct ports/security groups)","Use skip_clean = true if cleanup is not required for your workflow","Re-run the build; this often clears once the host is stable"],"exampleFix":"// before\nprovisioner \"shell\" {\n  scripts = [\"reboot.sh\"]\n  expect_disconnect = true\n}\n// after\nprovisioner \"shell\" {\n  scripts = [\"reboot.sh\"]\n  expect_disconnect = true\n  skip_clean = true\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {\n    if err := comm.Start(ctx, cmd); err != nil {\n        return fmt.Errorf(\"Error removing temporary script at %s: %s\", path, err)\n    }\n    return nil\n})","preventionTips":["Use skip_clean = true when leftover temp files are acceptable and cleanup connectivity is flaky","Ensure the machine is fully rebooted/reachable before the build finishes","Increase start_retry_timeout so cleanup survives reboot windows","Set remote_path in a stable location that outlives reboots (not tmpfs cleared on boot)"],"tags":["provisioner","shell","cleanup","communicator","ssh"],"backgroundTag":"remote-command-execution-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}