0

I am using a VM instance in Google Cloud Console to automatically run some python scripts but it doesn't seem to be working. I have a test script called "emailtest.py", the file path of which is C:\Users\username\emailtest.py. emailtest.py essentially just sends me an email and when I RDP into the instance it works fine. I also have a Powershell script called startupscript.ps1, the only commando of which is "python emailtest.py" and the file path is C:\Users\username\startupscript.ps1. I have tried to automatically run the script a few different ways:

Key: windows-startup-script-cmd, Value: python emailtest.py

Key: windows-startup-script-ps1, Value: C:\Users\username\startupscript.ps1

Key: windows-startup-script-url Value: gs://csvconversion/startup.ps1

I have been testing this by attaching this instance to an instance scheduler and letting it run for about 15 minutes at a time but I never receive an email. Is there anything that I might be missing here? Am I perhaps going about testing this incorrectly? Any help is greatly appreciated!

Rio Young
  • 1
  • 1
  • How is your script sends emails ? Did you try RDP'ing into the VM and running the script manually to see if you get the email ? – boredabdel Jul 27 '22 at 07:25
  • @boredabdel The code in emailtest.py is mostly from this [link](https://towardsdatascience.com/how-to-easily-automate-emails-with-python-8b476045c151) and it works when I run it both locally and in the VM. I also ran the startup script manually in the VM using Powershell and it worked okay. – Rio Young Jul 27 '22 at 14:50
  • You are storing your startup script relative to a user's home directory. Startup scripts run earlier in the system boot process and do not use a user's environment. Use the VM's serial console and view the startup logs files to see the error that occurs with your startup script. https://cloud.google.com/compute/docs/troubleshooting/troubleshooting-using-serial-console – John Hanley Jul 28 '22 at 06:35
  • @JohnHanley I checked the serial console and the errors seem to be: windows-startup-script-cmd: 'python' is not recognized as an internal or external command,operable program or batch file. windows-startup-script-url: python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. windows-startup-script-url: Can't find a default Python. None of these errors occur when I RDP into the VM. Do you know why this mught be happening or how I might go about resolving these issues? – Rio Young Aug 02 '22 at 17:03
  • Probably because you installed Python as a user. Install Python to be available to the entire system in a directory like `C:\Python`. Then specify the full Python path in your scripts: `C:\Python\python.exe C:\myscripts\main.py ...` – John Hanley Aug 02 '22 at 17:14

0 Answers0