Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 关闭脚本未在Google云VM上执行_Python_Google Cloud Platform_Virtual Machine_Google Compute Engine_Shutdown Script - Fatal编程技术网

Python 关闭脚本未在Google云VM上执行

Python 关闭脚本未在Google云VM上执行,python,google-cloud-platform,virtual-machine,google-compute-engine,shutdown-script,Python,Google Cloud Platform,Virtual Machine,Google Compute Engine,Shutdown Script,我有以下资料: #/usr/bin/python3.7 f=open(“python_out.txt”,“w”,encoding='utf-8') f、 写(“OK1”) 导入套接字 进口电报 f、 写(“OK2”) BOT\u TOKEN=“电报BOT\u TOKEN” CHAT\u ID=“CHAT\u ID” bot=电报.bot(令牌=bot\u令牌) host_name=socket.gethostname() 内容='计算机名称:%s正在关闭!'%主机名 bot.send_messa

我有以下资料:

#/usr/bin/python3.7
f=open(“python_out.txt”,“w”,encoding='utf-8')
f、 写(“OK1”)
导入套接字
进口电报
f、 写(“OK2”)
BOT\u TOKEN=“电报BOT\u TOKEN”
CHAT\u ID=“CHAT\u ID”
bot=电报.bot(令牌=bot\u令牌)
host_name=socket.gethostname()
内容='计算机名称:%s正在关闭!'%主机名
bot.send_message(chat_id=chat_id,text=content)
f、 写(“OK3”)
我已经检查了我的环境,我可以通过
python3 script.py
使这个脚本工作。当它在实例中时,它可以发送通知并输出
python\u out.txt

我在
关机脚本中设置了此脚本

但是当我手动点击“停止”按钮时,它并没有像预期的那样工作<代码>启动脚本

我读过很多帖子:

当然,它还包括官方文件:

我想尝试设置,但在GCP Ubuntu 16.04 LTS中找不到
/etc/acpi/


我找不到更多的时间表和想法了?

当您使用启动脚本和关闭脚本时,当前执行的用户是
root
用户和默认目录
/root/
。这个目录是不可写的,这就是为什么你的代码没有任何变化

只需将文件写入可写目录即可


不要忘记,您创建的文件是由
root
用户编写的,所有用户都不能读取和/或写入
root
用户编写的文件。使用
chmod
chown
来更改此设置。

您可以尝试用
f=open(“/tmp/python_out.txt”,“w”,encoding='utf-8')编写文件吗?
?告诉我它是否有效。如果是这样,我会向你解释issue@guillaumeblaquiere太神奇了!在我修改启动脚本并启动它之后,
tmp/python\u out.txt
存在,但它只打印到
print(OK1)
,但我非常确定我的环境是正确的。当我在实例连接中输入
/usr/bin/python3.7 telegrame_notification.py
时,它可以通过电报通知我,
telegrame_notification.py
的内容与启动脚本sameso相同,为什么不能通知它呢?同意,这是为了,并通过推断,我明白这也是关闭的理由。但是,我同意,这是不清楚的!我打开了一个问题