Skip to main content
added 54 characters in body
Source Link
WoJ
  • 1.7k
  • 2
  • 23
  • 45

If you are in a systemd machine, you can use a monotonic timer

The timer unit /etc/systemd/system/shutdown_after_an_hour.timer

[Unit]
Description=shutdown after an hour

[Timer]
OnBootSec=1h

[Install]
WantedBy=timers.target

The timer unit /etc/systemd/system/shutdown_after_an_hour.service:

[Unit]
Description=shutdown after an hour

[Service]
ExecStart=/sbin/poweroff --force --no-wall
Type=oneshot

It is enabled via

# systemctl enable shutdown_after_an_hour.timer

Its status (particularly how much time is left before the shutdown) is available via

# systemctl list-timers shutdown_after_an_hour.timer

It will work on the next reboot, it is not useful to systemctl start it during the session when it is created as it will either not work (because it was not triggered during the reboot) or shut down the machine right away if past one hour. I do not know which one will happen as a matter of fact, I have never tested that as I think of itspecific case.

If you are in a systemd machine, you can use a monotonic timer

The timer unit /etc/systemd/system/shutdown_after_an_hour.timer

[Unit]
Description=shutdown after an hour

[Timer]
OnBootSec=1h

[Install]
WantedBy=timers.target

The timer unit /etc/systemd/system/shutdown_after_an_hour.service:

[Unit]
Description=shutdown after an hour

[Service]
ExecStart=/sbin/poweroff --force --no-wall
Type=oneshot

It is enabled via

# systemctl enable shutdown_after_an_hour.timer

Its status (particularly how much time is left before the shutdown) is available via

# systemctl list-timers shutdown_after_an_hour.timer

It will work on the next reboot, it is not useful to systemctl start it during the session when it is created as it will either not work (because it was not triggered during the reboot) or shut down the machine right away if past one hour. I have never tested that as I think of it.

If you are in a systemd machine, you can use a monotonic timer

The timer unit /etc/systemd/system/shutdown_after_an_hour.timer

[Unit]
Description=shutdown after an hour

[Timer]
OnBootSec=1h

[Install]
WantedBy=timers.target

The timer unit /etc/systemd/system/shutdown_after_an_hour.service:

[Unit]
Description=shutdown after an hour

[Service]
ExecStart=/sbin/poweroff --force --no-wall
Type=oneshot

It is enabled via

# systemctl enable shutdown_after_an_hour.timer

Its status (particularly how much time is left before the shutdown) is available via

# systemctl list-timers shutdown_after_an_hour.timer

It will work on the next reboot, it is not useful to systemctl start it during the session when it is created as it will either not work (because it was not triggered during the reboot) or shut down the machine right away if past one hour. I do not know which one will happen as a matter of fact, I have never tested that specific case.

complete answer
Source Link
WoJ
  • 1.7k
  • 2
  • 23
  • 45

If you are in aIf you are in a systemd machine, you can use a monotonic timer

The timer unit /etc/systemd/system/shutdown_after_an_hour.timer machine, you can use a

[Unit]
Description=shutdown after an hour

[Timer]
OnBootSec=1h

[Install]
WantedBy=timers.target

The timer unit feature of timers/etc/systemd/system/shutdown_after_an_hour.service:

Monotonic timer

A timer which will start 15 minutes after boot and again every week while the system is running.

/etc/systemd/system/foo.timer
[Unit]
Description=Run foo weekly and on boot

[Timer]
OnBootSec=15min
OnUnitActiveSec=1w 

[Install]
WantedBy=timers.target
[Unit]
Description=shutdown after an hour

[Service]
ExecStart=/sbin/poweroff --force --no-wall
Type=oneshot

It is enabled via

# systemctl enable shutdown_after_an_hour.timer

Its status (particularly how much time is left before the shutdown) is available via

# systemctl list-timers shutdown_after_an_hour.timer

It will work on the next reboot, it is not useful to systemctl start it during the session when it is created as it will either not work (because it was not triggered during the reboot) or shut down the machine right away if past one hour. I have never tested that as I think of it.

If you are in a systemd machine, you can use a feature of timers:

Monotonic timer

A timer which will start 15 minutes after boot and again every week while the system is running.

/etc/systemd/system/foo.timer
[Unit]
Description=Run foo weekly and on boot

[Timer]
OnBootSec=15min
OnUnitActiveSec=1w 

[Install]
WantedBy=timers.target

If you are in a systemd machine, you can use a monotonic timer

The timer unit /etc/systemd/system/shutdown_after_an_hour.timer

[Unit]
Description=shutdown after an hour

[Timer]
OnBootSec=1h

[Install]
WantedBy=timers.target

The timer unit /etc/systemd/system/shutdown_after_an_hour.service:

[Unit]
Description=shutdown after an hour

[Service]
ExecStart=/sbin/poweroff --force --no-wall
Type=oneshot

It is enabled via

# systemctl enable shutdown_after_an_hour.timer

Its status (particularly how much time is left before the shutdown) is available via

# systemctl list-timers shutdown_after_an_hour.timer

It will work on the next reboot, it is not useful to systemctl start it during the session when it is created as it will either not work (because it was not triggered during the reboot) or shut down the machine right away if past one hour. I have never tested that as I think of it.

Source Link
WoJ
  • 1.7k
  • 2
  • 23
  • 45

If you are in a systemd machine, you can use a feature of timers:

Monotonic timer

A timer which will start 15 minutes after boot and again every week while the system is running.

/etc/systemd/system/foo.timer
[Unit]
Description=Run foo weekly and on boot

[Timer]
OnBootSec=15min
OnUnitActiveSec=1w 

[Install]
WantedBy=timers.target