I have the following:
#! /usr/bin/python3.7
f=open("python_out.txt",'w',encoding='utf-8')
f.write("OK1")
import socket
import telegram
f.write("OK2")
BOT_TOKEN = "telegram BOT_TOKEN"
CHAT_ID = "chat_id"
bot = telegram.Bot(token=BOT_TOKEN)
host_name = socket.gethostname()
content = 'Machine name: %s is shutting down!' % host_name
bot.send_message(chat_id=CHAT_ID, text=content)
f.write("OK3")
I have checked my environment, I can make this script work through python3 script.py
when it is in the instance,It can send notifications and output python_out.txt
.
I set this script in shutdown-script
But when I manually clicked the "stop" button, it did not work as expected. startup-script
too.
I have read many posts:
- Shutdown script not executing on a Google Cloud VM
- Reliably executing shutdown scripts in Google Compute Engine
- Pro Tip: Use Shutdown Script Detect Preemption on GCP
Of course it also includes official documents:
I want to try setting powerbtn.sh,but i can't find /etc/acpi/
in GCP Ubuntu 16.04 LTS
I can't find any more schedule, any ideas?