0

I have the following file /etc/cron.d/my_tasks and I would like to know how to set the environment variables within this file.

Previously I had it set up like this:

0 5 * * * root . /root/.profile path/to/my/task

But I would like to not have to explicitly have root set here, I would like to have something like:

0 5 * * * . $HOME.profile path/to/my/task

From what I have read though, Cron will not load the environment variables the same way for files inside cron.d as it would within /etc/crontab

Is it possible to load the environment variables in a similar way to what I am attempting?

Thanks

Ben Currie
  • 25
  • 6
  • Why not replacing `$HOME` with the full path to the user's home? – Avihoo Mamka Feb 08 '19 at 15:13
  • @AvihooMamka I was hoping to avoid having to specify the full path and just use the environment variables but from what I've read the environment variables are not the same within these files. So I'm more curious to see if I can load the environment variables into these files the same way that you can within /etc/crontab – Ben Currie Feb 08 '19 at 15:17
  • Have you tried that [solution](https://stackoverflow.com/a/34492957/2455626)? – Avihoo Mamka Feb 08 '19 at 15:23
  • Yeah I tried that before but it doesn't seem to be working for me. Thanks for your help, I'll keep looking around for more possible answers – Ben Currie Feb 08 '19 at 15:32

0 Answers0