How can I shutdown the system after 3 minutes automatically.

Dani AI

Generated

and pointed to the usual approach using the system shutdown tool, which is perfectly fine for interactive use. A few practical additions and alternatives that are useful on modern Linux systems follow — they avoid repeating the exact examples already shown and add ways to schedule, cancel, and troubleshoot a delayed power-off.

One clean systemd-native way is to create a transient timer that runs a poweroff when it fires:

sudo systemd-run --on-active=3min --unit=delayed-shutdown /bin/systemctl poweroff

This creates a short-lived timer + service unit; cancel or inspect it with systemctl list-timers --all and stop the timer unit if needed. See the systemd-run manual for details: systemd-run manual.

If systemd-run is not desirable, two other simple options are: schedule a one-shot job with at, or spawn a background sleep that runs poweroff after 180 seconds. Examples:

echo "systemctl poweroff" | at now + 3 minutes
nohup bash -c 'sleep 180 && sudo systemctl poweroff' >/dev/null 2>&1 &

To cancel a scheduled shutdown created by the shutdown utility, use its cancel option; for systemd-run timers stop the timer unit as shown above. If a scheduled action does not occur, check journal logs (journalctl -xe) and systemd-inhibit --list (GUI apps can block shutdown), and confirm the machine isn’t suspended or lacking permission to power off.

For the classic shutdown utility and behavior, see the man page: shutdown(8). Keep in mind scheduled power-off will terminate sessions — ensure work is saved before testing on production systems.

Recommended Answers

All 3 Replies

shutdown -P +3 should work.

-P means power off. You can alternatively use -r to reboot. You can use +3 to shutdown in 3 minutes, or "now" to happen right now.

You can use the shutdown command + option like below.
$ sudo shutdown -h +3

I looked it up and it seems the -h and -P commands do the same thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.