在Linux系统中,可以通过设置系统服务或者使用定时任务来让服务器挂机。以下是两种常用的方法:
设置系统服务:
[Unit] Description=Shutdown the server [Service] Type=oneshot ExecStart=/sbin/shutdown -h now [Install] WantedBy=multi-user.target /etc/systemd/system/目录下。sudo systemctl enable shutdown.service sudo systemctl start shutdown.service sudo systemctl stop shutdown.service来取消挂机操作。使用定时任务:
crontab -e命令编辑当前用户的定时任务。0 0 * * 0 /sbin/shutdown -h now 通过以上方法设置好后,服务器会在指定时间自动执行关机操作,实现挂机的效果。