How do I send a scheduled shutdown command to a user in Linux?

Mondo Technology Updated on 2024-02-23

How do I send a scheduled shutdown command to a user in Linux?

In Linux, you can use the shutdown command to schedule a shutdown. Here's how to use the shutdown command to set up a scheduled shutdown:

1.*Immediate Power Off**:

sudo shutdown -h now

2.*Shut down at the specified time**:

If you want to shut down at a specific time (e.g., 10 p.m.), you can use the + sign followed by the date and time:

sudo shutdown -h +10 "Shut down at 10pm"

Here, +10 means 10 minutes later.

3.*Delayed shutdown**:

If you want to shut down after a certain period of time, e.g. after 30 minutes:

sudo shutdown -h +30 "Turn off after 30 minutes"

4.*Cancel Shutdown**:

If you want to cancel the previous shutdown schedule, you can use the following command:

sudo shutdown -c

5.*Scheduled restart**:

In addition to shutting down, you can also schedule a reboot. Using a command similar to the one above, replace -h with -r.

6.Set Default Message:

When the system is about to shut down, it displays a message on the terminal. You can set the default message:

sudo shutdown -h -m "This is the default message" now

7.*Scheduled shutdown with cron task**:

You can also use cron tasks to schedule shutdowns. Edit the cron table:

crontab -e

Then, add a line like this to schedule the shutdown:

reboot /sbin/shutdown -h +5 "Power off after 5 minutes"

Here, @reboot means that this command will be run every time it starts.

8.Note: There may be slight differences between Linux distributions, so the above commands may need to be adjusted for your specific system. If the command doesn't work, reviewing the relevant documentation or resources may help.

#linux#

If you want to know more exciting content, come and pay attention.

Related Pages