帮我写一个自动关机脚本
时间: 2023-06-02 21:02:12 浏览: 207
由于你没有说明你使用的是哪个操作系统,这里我提供的是Windows和Linux的自动关机脚本。
Windows自动关机脚本:
在桌面上新建一个文本文件,将以下代码复制并粘贴进去:
```
@echo off
echo 此计算机将在10秒后自动关机,请保存好您的工作!
shutdown -s -t 10
```
将文件保存为“autoshutdown.bat”(注意扩展名必须为.bat)。
双击运行该文件即可自动关机。
Linux自动关机脚本:
打开终端,输入以下命令:
```
sudo shutdown -h +30
```
其中“30”表示30分钟后自动关机,可以根据需要调整。
运行该命令后,系统会在指定的时间自动关机。如果要取消自动关机,可以使用以下命令:
```
sudo shutdown -c
```
希望能帮到你!
相关问题
帮我写一个自动关机的电脑脚本
当然可以,以下是Python脚本实现自动关机功能:
```python
import os
os.system("shutdown /s /t 0")
```
这个脚本会在运行后立即关机电脑。如果你想要延迟关机,可以修改第二行的时间参数,单位为秒。例如,如果你想要10分钟后关机,可以这样写:
```python
os.system("shutdown /s /t 600")
```
你可以将这个脚本保存为一个.py文件并运行,或者在命令行中直接复制粘贴代码并执行。注意:关机前请保存好所有重要的文件。
写个centos自动关机脚本
Sure, here's a simple shell script in CentOS that will automatically shut down the system after a specified amount of time:
```
#!/bin/bash
# Set the amount of time to wait before shutting down
time_to_wait=60
# Display a message to the user
echo "System will shut down in $time_to_wait seconds."
# Wait for the specified amount of time
sleep $time_to_wait
# Shut down the system
shutdown -h now
```
Save this script as a file with a `.sh` extension, make it executable with `chmod +x filename.sh`, then run it with `./filename.sh`. The system will shut down after 60 seconds. You can adjust the `time_to_wait` variable to set a different amount of time.
阅读全文
相关推荐









