5

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:

FPATH=/very/long/path/to/binary
2

3 Answers 3

9

This perfectly works, ie

$ crontab -l
TESTDIR=/home/user/test

* * * * * "$TESTDIR"/script.sh

Have a look at

man 5 crontab

more info is found there.

2

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

-1

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.

1
  • The environment set up for running the commands in a crontab is described in crontab(5). This may well differ between distributions of Linux.
    – Kusalananda
    Commented Sep 11, 2019 at 12:38

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.