Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Tiggum
Oct 24, 2007

Your life and your quest end here.


Problem description: I looked up how to schedule tasks in Linux and the answer I found was to use crontab. So I followed the instructions and set up a couple of test cases. When I type crontab -l I see:

45 16 * * * vivaldi http://radio.abc.net.au/stations/triplej/live?play=true
50 16 * * * mate-calc


My understanding was that my web browser (Vivaldi) should open up at 4:45pm to the Triple J listen live page, and five minutes later the calculator app should open. Those commands work fine when typed straight into the terminal. But nothing happened at 16:45 or at 16:50. As far as I can tell, absolutely nothing at all.

Attempted fixes: I tried setting the times to UTC in case it wanted that instead of local time, but that also didn't do anything.

Recent changes: None.

--

Operating system: Linux Mint 17.3 'Rosa' MATE 64 bit

Location: Australia

I have Googled and read the FAQ: Yes

Adbot
ADBOT LOVES YOU

telcoM
Mar 21, 2009
Fallen Rib

Tiggum posted:

Problem description: I looked up how to schedule tasks in Linux and the answer I found was to use crontab. So I followed the instructions and set up a couple of test cases. When I type crontab -l I see:

45 16 * * * vivaldi http://radio.abc.net.au/stations/triplej/live?play=true
50 16 * * * mate-calc


My understanding was that my web browser (Vivaldi) should open up at 4:45pm to the Triple J listen live page, and five minutes later the calculator app should open. Those commands work fine when typed straight into the terminal. But nothing happened at 16:45 or at 16:50. As far as I can tell, absolutely nothing at all.

You seem to be trying to run GUI programs from crontab.

In Linux, a GUI program uses X Window System, which has certain requirements.

First, the program must have the $DISPLAY environment variable set to a valid value - your graphical login session and all its terminals will have that, but any processes started from crontab won't. Neither will any login sessions on text-based virtual consoles, or remote SSH sessions: if you are using SSH with X-forwarding, then that session will have a different $DISPLAY value.

Second, there is a file in your home directory: ~/.Xauthority. It contains a "session cookie": without access to a valid cookie, the display server will reject the application. Each time the X display server is restarted or you log out, the server regenerates the cookie. At GUI login, your session gets a copy of it.

Third, access to sound devices is typically restricted to whoever is currently logged on the system locally, by default. This is usually managed by PAM and other componets as a part of the login/logout process. You'll need to do something to grant your account permission to access sound devices even without an active local login session: in most modern distributions, this can usually be achieved by adding your account to the "audio" user group. This is a simple command that you'll need to do only once:
code:
sudo usermod -a -G audio <your_username>
The cron scheduler assumes any commands you schedule should be capable of running in a non-interactive, or "headless" mode: their standard input will be /dev/null, and standard output and error output will be redirected into a file, and then sent to your local email account: you'll probably find two emails with some variations of "Could not connect to display" error messages in the /var/mail/<your_username> file, which is your local system mailbox.

You might want to set up a script that prepares the necessary things and then runs the browser with the desired URL.
Here are the things your script would need to do:

1.) Setting up the $DISPLAY environment variable would be easy: the value for "the default local display on this computer" is ":0.0".
code:
export DISPLAY=":0.0"
2.) If you are currently logged in when the cron job fires, your home directory will already contain the ~/.Xauthority file with the correct cookie. But if someone else - or nobody - is logged in, you'll need sudo access to get the session cookie from wherever the X display manager process (gdm, kdm or <something>dm) keeps it.

For example, on my Debian 9 with KDE, the location of the master session cookie file is visible in the process listing:
code:
$ ps ax |grep X
 1928 tty7     Ssl+   9:06 /usr/lib/xorg/Xorg -nolisten tcp -auth /var/run/sddm/{eb90233a-f54d-4712-b8a3-0359e0e9b4e5} -background none -noreset -displayfd 18 vt7
The parameter to the X server's -auth option is what we want. However, the file is accessible for root only, and the filename may vary from one session to the next.
Here's an one-liner for grabbing a copy of it and adding it to your ~/.Xauthority file, once the filename is known:
code:
sudo xauth -f /var/run/sddm/{eb90233a-f54d-4712-b8a3-0359e0e9b4e5} nlist :0.0 | xauth nmerge -
Note: I don't know how Linux Mint stands in regards of Wayland - that might bring some new requirements to this process.

3.) Now the preparations are done and your script can start the browser. Or the calculator, if you wish.

Tiggum
Oct 24, 2007

Your life and your quest end here.


OK, looks like this is way too complicated for me, I'll have to find some other solution. Thanks anyway.

Viscart
Oct 25, 2017

Tiggum posted:

OK, looks like this is way too complicated for me, I'll have to find some other solution. Thanks anyway.
Read a basic tutorial on crontab, install mplayer/mpv, set up an alarm by arranging a certain sound file to be played at a certain time.

Alternatively, if you're a masochist, count the number of seconds until the desired time and use sleep instead of crontab.

I'm sure there are GUI programs on Linux these days that can do what you want. Especially as part of desktop environments. If you give that up, you'll have to resort to the terminal or find a program with a short list of dependencies.

Tiggum
Oct 24, 2007

Your life and your quest end here.


Viscart posted:

Read a basic tutorial on crontab, install mplayer/mpv, set up an alarm by arranging a certain sound file to be played at a certain time.
The point was to have the radio come on so I can listen to the news in bed. I used to use a clock radio but I get absolutely terrible reception in the house I just recently moved into.

I ended up just using my Windows computer instead. It's slightly less convenient, but it works.

  • Locked thread