Skip to main content
Add link to explanation of exec, plus minor grammar changes.
Source Link

You could invoke bash with the -l option, like this:

* * * * * /bin/bash -l /path/to/script arg1 arg2 

The -l option makes bash a login shell. Thus, it will read the user's .bash_profile. It won't read the user's .bashrc unless it is explicitly sourced by .bash_profile. This is because non-interactive shells don't automatically read .bashrc. But you shouldn't need .bashrc for a cron job because. .bashrc is for setting things useful for anto interactive shellshells, like setting PS1 and creating aliases.

Variations:

If bash is on the PATH, there's no need to specify an absolute path to it:

* * * * * bash -l /path/to/script arg1 arg2 

AAn optimization would be to replace the current shell by using exec:

* * * * * exec bash -l /path/to/script arg1 arg2 

See Why do some Linux shell scripts use exec to run commands? for discussion of the use of exec.

You could invoke bash with the -l option, like this:

* * * * * /bin/bash -l /path/to/script arg1 arg2 

The -l option makes bash a login shell. Thus, it will read the user's .bash_profile. It won't read the user's .bashrc unless it is explicitly sourced by .bash_profile. This is because non-interactive shells don't automatically read .bashrc. But you shouldn't need .bashrc for a cron job because .bashrc is for setting things useful for an interactive shell.

Variations:

If bash is on the PATH, there's no need to specify an absolute path:

* * * * * bash -l /path/to/script arg1 arg2 

A optimization would be to replace the current shell by using exec:

* * * * * exec bash -l /path/to/script arg1 arg2 

You could invoke bash with the -l option, like this:

* * * * * /bin/bash -l /path/to/script arg1 arg2 

The -l option makes bash a login shell. Thus, it will read the user's .bash_profile. It won't read the user's .bashrc unless it is explicitly sourced by .bash_profile. This is because non-interactive shells don't automatically read .bashrc. But you shouldn't need .bashrc for a cron job. .bashrc is for setting things useful to interactive shells, like setting PS1 and creating aliases.

Variations:

If bash is on the PATH, there's no need to specify an absolute path to it:

* * * * * bash -l /path/to/script arg1 arg2 

An optimization would be to replace the current shell by using exec:

* * * * * exec bash -l /path/to/script arg1 arg2 

See Why do some Linux shell scripts use exec to run commands? for discussion of the use of exec.

Source Link

You could invoke bash with the -l option, like this:

* * * * * /bin/bash -l /path/to/script arg1 arg2 

The -l option makes bash a login shell. Thus, it will read the user's .bash_profile. It won't read the user's .bashrc unless it is explicitly sourced by .bash_profile. This is because non-interactive shells don't automatically read .bashrc. But you shouldn't need .bashrc for a cron job because .bashrc is for setting things useful for an interactive shell.

Variations:

If bash is on the PATH, there's no need to specify an absolute path:

* * * * * bash -l /path/to/script arg1 arg2 

A optimization would be to replace the current shell by using exec:

* * * * * exec bash -l /path/to/script arg1 arg2