统信操作系统UOS1060设置自动关机02
  qkadZYAX5eto 2023年11月02日 55 0

原文链接:统信UOS1060设置自动关机02

hello,大家好啊,今天继续给大家介绍一篇如何在统信UOS 1060上实现自动关机的文章,本篇文章采用创建系统服务(Systemd)的方式。

你可以创建一个systemd服务来在特定时间执行关机命令。这需要创建一个服务文件和一个timer文件。Timer文件定义了何时运行服务。它可以定时或按照特定的时间表运行服务

1、创建服务文件

创建一个新的服务文件,例如 /etc/systemd/system/auto-shutdown.service,并添加以下内容
[Unit] :部分包含了服务的描述。
Description=Automatically shut down the system :是对服务的描述,说明这是一个用于自动关机的服务。
[Service] :部分定义了服务的详细信息。
Type=oneshot :表示这个服务会执行一次然后退出。
ExecStart=/usr/sbin/poweroff :定义了服务启动时要执行的命令,即关机命令。
uos@uos-PC:~/Desktop$ sudo -i
请输入密码:
验证成功
root@uos-PC:~# vi /etc/systemd/system/auto-shutdown.service
root@uos-PC:~# cat /etc/systemd/system/auto-shutdown.service
[Unit]
Description=Automatically shut down the system
[Service]
Type=oneshot
ExecStart=/usr/sbin/poweroff
root@uos-PC:~#

统信操作系统UOS1060设置自动关机02_文件创建

2、创建timer文件

创建一个与服务文件相关联的timer文件,例如 /etc/systemd/system/auto-shutdown.timer,并添加以下内容
[Unit] :部分包含了timer的描述。
Description=Run auto-shutdown.service at a specific time :是对timer的描述,说明这个timer是用来在特定时间运行auto-shutdown.service服务的。
[Timer] :部分定义了timer的详细信息。
OnCalendar=*-*-* 14:35:00 :定义了timer触发的时间,即每天的23:00:00。
Unit=auto-shutdown.service :定义了当timer触发时要运行的服务,即auto-shutdown.service。
[Install] :部分定义了timer的安装信息。
WantedBy=timers.target :表示这个timer应该被timers.target所需要,确保timer在系统启动时被激活。
root@uos-PC:~# vi /etc/systemd/system/auto-shutdown.timer
root@uos-PC:~# cat /etc/systemd/system/auto-shutdown.timer
[Unit]
Description=Run auto-shutdown.service at a specific time
[Timer]
OnCalendar=*-*-* 14:35:00
Unit=auto-shutdown.service
[Install]
WantedBy=timers.target
root@uos-PC:~#

统信操作系统UOS1060设置自动关机02_linux_02

3、启动和启用timer

运行以下命令来启动并启用timer:

root@uos-PC:~# systemctl start auto-shutdown.timer
root@uos-PC:~# systemctl enable auto-shutdown.timer
Created symlink /etc/systemd/system/timers.target.wants/auto-shutdown.timer → /etc/systemd/system/auto-shutdown.timer.
root@uos-PC:~#

统信操作系统UOS1060设置自动关机02_系统服务_03

4、系统到时间自动关机

统信操作系统UOS1060设置自动关机02_系统启动_04

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  6YY0QMPUXEwu   2023年12月10日   31   0   0 linux网卡
  nIt0XG0acU8j   2023年12月11日   32   0   0 linuxhtop
  nIt0XG0acU8j   2023年12月09日   36   0   0 linuxsort
qkadZYAX5eto