Cronjobs run as whatever user set the crontab up. They don't run as a special user. Usually, if you know a crontab exists, you know who set it up. You can see the crontabs of the current user by running
crontab -l
You can find user-specific crontabs in the directory /var/spool/cron/crontabs/
. Each user who has created a crontab will have a file (whose name is the user's name) in that directory. By default, those files are only readable by the user who created them, so you cannot cat
them without playing around with their permissions.
This little scriptlet will list all cron commands for each user:
for u in $(find /var/spool/cron/crontabs/ -type f); do
user=`basename $u`;
echo "------- $user ----";
crontab -u $user -l | grep -v "#";
done
That will list all cronjobs for each of the users that have a crontab file in /var/spool/cron/crontabs/
.
Finally, you also have the system-wide crontabs that are in /etc/crontab
which you can see by running cat /etc/crontab
.
In answer to your comment, if you want to load specific variables that are defined in a given file, you can source
that file in your crontab
:
42 13 * * * . ~/.bashrc && cd /path/to/my/working/folder && /path/to/my/working/folder/script/runner 'MusicService.update_cached_data' -e staging
That is .
followed by the file you want to load.
Finally, here is some relevant information from man 5 crontab
:
An active line in a crontab will be either an envi‐
ronment setting or a cron command. The crontab file
is parsed from top to bottom, so any environment set‐
tings will affect only the cron commands below them
in the file. An environment setting is of the form,
name = value
where the spaces around the equal-sign (=) are
optional, and any subsequent non-leading spaces in
value will be part of the value assigned to name.
The value string may be placed in quotes (single or
double, but matching) to preserve leading or trailing
blanks. To define an empty variable, quotes must be
used. The value string is not parsed for environmen‐
tal substitutions or replacement of variables, thus
lines like
PATH = $HOME/bin:$PATH
will not work as you might expect.
An alternative for setting up the commands path is
using the fact that many shells will treat the
tilde(~) as substitution of $HOME, so if you use bash
for your tasks you can use this:
SHELL=/bin/bash
PATH=~/bin:/usr/bin/:/bin
[...]
Several environment variables are set up automati‐
cally by the cron(8) daemon. SHELL is set to
/bin/sh, and LOGNAME and HOME are set from the
/etc/passwd line of the crontab's owner. PATH is set
to "/usr/bin:/bin". HOME, SHELL, and PATH may be
overridden by settings in the crontab; LOGNAME is the
user that the job is running from, and may not be
changed.
[...]
On the Debian GNU/Linux system, cron supports the
pam_env module, and loads the environment specified
by /etc/environment and /etc/security/pam_env.conf.
It also reads locale information from
/etc/default/locale. However, the PAM settings do
NOT override the settings described above nor any
settings in the crontab file itself. Note in particu‐
lar that if you want a PATH other than
"/usr/bin:/bin", you will need to set it in the
crontab file.
[...] 'MusicService.update_cached_data' -e staging 2> ~/error