Schedule linux task (Cron)

Asked

Viewed 155 times

4

How to open a file and shut down your computer with crontab?

Follow my attempt:

30 07 * * * killall qbittorrent (funcionando)
50 07 * * * shutdown -r 1 "Desligando desktop" (não funciona)
30 12 * * * qbittorrent & (não funciona)
55 13 * * * killall qbittorrent (funcioando)
08 20 * * * qbittorrent & (não funciona)
  • 1

    Already tried this 30 23 * * * root shutdown -h now?

  • @Viniciuszaramella already Feb 12 16:13:01 CRON magnet[9147]: (root) CMD (shutdown -h now)

1 answer

1


The following commands worked for me (I used firefox in place of qbittorrent because I don’t have qbittorrent installed):

$ sudo su

to log in as root and nay change the global crontab table (located in /etc/crontab).

$ crontab -e

to change the root user crontab, with the following entries:

29 * * * * killall firefox
30 * * * * sudo shutdown -r now
35 * * * * su USUARIO -c "DISPLAY=:0.0 firefox"
36 * * * * killall firefox
37 * * * * su USUARIO -c "DISPLAY=:0.0 firefox"

Where USUARIO can be any user of your system with which you wanted to run the command.

I believe your command just wasn’t working because $DISPLAY was not defined, and the program cron doesn’t understand anything about displaying things on the screen.

  • That’s right, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.