(Solved)Auto shutdown at 10:30PM daily

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
opale7000

(Solved)Auto shutdown at 10:30PM daily

Post by opale7000 »

Hello All

What would be a way for me to auto shutdown my computer everyday at 10:30PM :?:

Linux mint 18.1 Cinnamon

8)
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
now3by
Level 2
Level 2
Posts: 68
Joined: Mon Jan 23, 2017 1:56 pm

Re: Auto shutdown at 10:30PM daily

Post by now3by »

crontab is your friend:

sudo crontab -e

and add this lines:

Code: Select all

# shutdown every night at 22:30
30 22    * * *    /sbin/shutdown -h now
Linux...
acerimusdux
Level 5
Level 5
Posts: 633
Joined: Sat Dec 26, 2009 3:36 pm

Re: Auto shutdown at 10:30PM daily

Post by acerimusdux »

This is one of those that might have more than one good answer.

But I think the typical unix way would be to run a cron job. Which you can do by editing your crontab file. The following for example would add the needed line to /etc/crontab:

Code: Select all

sudo bash -c 'echo "30 22   * * *   root    /sbin/shutdown -h now" >> /etc/crontab'
The line actually added to the file is everything between the " quotes. You could also just open an editor as root and add this line. The 30 22 is just minutes, hours (in 24 hr format), so means 10:30 PM. The three stars after that indicate to run every day, every month, every day of the week. Then you have the user to run the command, and the command to be run.

edit: ah, now3by beat me to it. And using crontab -e looks like the easiest way to edit the file.
Last edited by acerimusdux on Mon Jun 12, 2017 1:14 pm, edited 1 time in total.
opale7000

Re: Auto shutdown at 10:30PM daily

Post by opale7000 »

Agreed that there numerous ways to shut down and will try the following for tonight

Code: Select all

# m h  dom mon dow   command

30 22 * * * sudo poweroff

And if no go will try your other options. Thanks guys
acerimusdux
Level 5
Level 5
Posts: 633
Joined: Sat Dec 26, 2009 3:36 pm

Re: Auto shutdown at 10:30PM daily

Post by acerimusdux »

Don't think you want to run sudo from crontab. If you use roots crontab (in /etc/crontab, accessed by sudo crontab -e) it will already run with root permissions. And actually, you don't need to be root to run shutdown in Mint. So you could just do crontab -e, and add the poweroff -h command there.
opale7000

Re: Auto shutdown at 10:30PM daily

Post by opale7000 »

acerimusdux wrote:Don't think you want to run sudo from crontab. If you use roots crontab (in /etc/crontab, accessed by sudo crontab -e) it will already run with root permissions. And actually, you don't need to be root to run shutdown in Mint. So you could just do crontab -e, and add the poweroff -h command there.
Much appreciated. Will revise. Thanks
opale7000

Re: Auto shutdown at 10:30PM daily

Post by opale7000 »

Only gsShutdown app does the job. All crontab commands do not work for me.
Locked

Return to “Scripts & Bash”