1

I have a cron job that runs emacsclient which requires that XDG_RUNTIME_DIR to be set. I can set the variable to something like /run/user/1000 in the crontab but then this assumes that the owner of the cron is the first user to login (otherwise their XDG_RUNTIME_DIR would be /run/user/1001 for example).

Is there a better way to have cron inherit the value of XDG_RUNTIME_DIR from the owner of the cron jobs?

3
  • does your cron job run as user with uid 1000? Otherwise, this sounds like a bad idea. Do you really need to run emacsclient, even if that user is not logged into an X session? I ask because there's very likely an easier solution (I don't have one better than actually running a login shell, which runs a script, which runs your emacsclient). I mean, emacsclient makes no sense if there's not already an emacs running that it can communicate with, so there's very many reasons this sounds like an XY Problem. Jan 4, 2022 at 13:51
  • 1
    emacs.stackexchange.com/a/61778 please see this. This could be done on a per-user basis, based on who runs the crontab
    – Alex
    Jan 4, 2022 at 13:55
  • Thanks @Alex, this question is almost a duplicate to the one you link and the solution works as suggested.
    – Tohiko
    Jan 4, 2022 at 14:59

1 Answer 1

0

Suggesting to:

write dedicated cron script:

Include current user's environment context and additional environment variables.

cat << EOF > $HOME/croned_script.sh
#!/bin/bash
source $HOME/.bash_profile
export XDG_RUNTIME_DIR=/run/user/1000
#
# your program and arguments from here:
emacsclient
EOF

append dedicated cron script to crontab list:

In this example the cron pattern runs once at 12:00 noon each day

contab -l| sed "-i * 11 * * * bash -c $HOME/croned_script.sh"| crontab
1
  • 1
    It's worth to note that setting the variable doesn't automatically create a mount for the user directory in "/run/user". The directory "/run/user/1000" is created by systemd. CRON doesn't create it. Mar 3 at 18:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .