0

I know that I try to work to late in the night and that at this time I'm absolutely unproductive, I work for 5 minutes then switch to a link seen on youtube, then come back to my work, waste some more time on he internet... until 2 in the morning, hour at which I am able to discplinate myself and go to bed.

How could I write a script that automatically shuts down the computer at midnight?

I think I have to use the command crontab and write the following command in it

shutdown 00:00

I'm asking you if what I do is right, first and optimal or if it exists other ways to do it.

Here is what I made

myComputer:~$ crontab -l
# m h  dom mon dow   command
 55 23 *   *   *     /home/Marine1/soundOfSilence
 00 00 *   *   *     shutdown

Here is what is within /home/Marine1/soundOfSilence

#!/bin/bash

mpg123 /path/to/short/sound.mp3
shutdown 5
3
  • connect the server to a relay, and shutdown down your lights till 7AM ;) Commented Apr 3, 2016 at 14:26
  • @RuiFRibeiro, I don't understand the joke... I'm not native... :/ :'( Commented Apr 4, 2016 at 11:45
  • half truth, half joke...aliexpress.com/item/… Electrical relays, they can be commanded to turn on/off lights or electrical appliances. I have one connected to my "Raspberry"-like device. Commented Apr 4, 2016 at 12:03

1 Answer 1

3

I'd suggest doing something a bit different. Your approach is fine, but might prove annoying, when you got to do something sometime late and PC shuts down in the middle of the work. Instead, I'd suggest that you write a simple script that does something to bring your attention few minutes before shutdown, so you can prepare yourself.

The simplest approach would be to just run shutdown with 5 minute delay - it sends a warning. However, it might not be enough, and if you want to make sure that you notice it, you might do something more invasive, e.g. play some sound.

Example script would look more or less like this(I hope it's correct):

#!/bin/bash

mpg123 /path/to/short/sound.mp3
shutdown 5

mpg123 can be used to play audio MPEG. If you choose other format, you will need to change the command, but it should be easy enough to google.

7
  • That sounds great! But what would the script be then? Commented Apr 3, 2016 at 14:51
  • @Marine1 please see if I answered your question now. Commented Apr 4, 2016 at 0:00
  • I'm trying tonight and let you know if it worked! Commented Apr 4, 2016 at 11:43
  • I checked a bit:Marine1:~$ /path/to/short/sound.mp3 bash: /path/to/short/sound.mp3: No such file or directory But I think I can change it to something I find in my laptop, isn't it? Commented Apr 4, 2016 at 20:36
  • @Marine1 well, the file should not exist. It was an example to show that you need to create a short sound in MPEG format, and then provide a full path to that location. Commented Apr 4, 2016 at 20:39

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.