Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

On our linux server we have a lot of entries.

Many entries look like this:

15 13 * * 3 /very/long/path/to/binary/run.sh ...

These entries would be easier to maintain if I could write:

15 13 * * 3 $FPATH/run.sh

Where could I write this mapping:

share|improve this question

marked as duplicate by Anthon, Flup, Zelda, slm, Timo Mar 13 '14 at 15:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

This answer already covers your question Where can I set environment variables that crontab will use? – X Tian Mar 13 '14 at 10:18
also partial answser here unix.stackexchange.com/a/117470/53092 – Kiwy Mar 13 '14 at 10:19
@Kiwy this is not a dupe of that question. Setting variables in your profile or bashrc, even the system ones will not make them available in the crontab. – casey Mar 13 '14 at 14:54
@casey sorry I though it would – Kiwy Mar 13 '14 at 14:54
up vote 3 down vote accepted

This perfectly works, ie

$ crontab -l

* * * * * $TESTDIR/script.sh

Have a look at

man 5 crontab

more info is found there.

share|improve this answer

Simply embed this in the crontab itself, e.g. put your FPATH line (without spaces) as the first line of the crontab.

share|improve this answer

May you have a look at the Arch Wiki (https://wiki.archlinux.org/index.php/Environment_variables). In the section "Defining variables globally" you find this answer:

Most Linux distributions tell you to change or add environment variable definitions in /etc/profile or other locations. Be sure to maintain and manage the environment variables and pay attention to the numerous files that can contain environment variables. In principle, any shell script can be used for initializing environmental variables, but following traditional UNIX conventions, these statements should be only be present in some particular files. The following files should be used for defining global environment variables on your system: /etc/profile, /etc/bash.bashrc and /etc/environment.

PS: I am at work and can't test it. Hope it works.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.