I run jupyter noteboook on a server.

To start it, I have the following script:

exec &> /home/user/logfile2.txt

echo 'running jup.sh' >> /home/user/logfile2.txt

cd /home/user/jup
pipenv run jupyter notebook &

My sudo crontab file looks like:

@reboot sleep 20 && /usr/scripts/jup.sh

It has also looked like:

@reboot sleep 20 && /usr/scripts/jup.sh &    -or-
@reboot sleep 20 && /home/user/jup.sh &      -or- 
@reboot (sleep 20 && /usr/scripts/jup.sh) > /dev/null 

The script will output the file echo portion of the file, and I've echo'd out the working directory as well. As far as I can tell the only thing that doesn't execute is the "pipenv ..." command.

  1. I recently upgraded from 17.10, to 18.04 LTS. It used to work under the 'regular' crontab instead of the sudo.
  2. The script will start the jupyter notebook at the shell.

EDIT 1: I implemented the recommendations to add the full path for pipenv and for . /etc/profile. Neither resolved the issue.

I also deleted the first line of the script and received a mail stating that it couldn't find the full path. It said that it needed the full path. I added the full path and that error went away. Therefore, the full path was part of my problem.

I have a similar script that runs a gunicorn server for a django app. It too works from the shell, but not from @reboot. It too used to work with @reboot.

Edit 2: Email received about the error: (This has been fixed by adding the path)

From root@experiments.local  Thu Jun 13 11:25:23 2019
Return-Path: <root@experiments.local>
X-Original-To: root
Delivered-To: root@experiments.local
Received: by experiments.local (Postfix, from userid 0)
    id 05966E144D; Thu, 13 Jun 2019 11:25:23 -0700 (PDT)
From: root@experiments.local (Cron Daemon)
To: root@experiments.local
Subject: Cron <root@experiments> (sleep 20 && /usr/scripts/jup.sh)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20190613182523.05966E144D@experiments.local>
Date: Thu, 13 Jun 2019 11:25:23 -0700 (PDT)

/usr/scripts/jup.sh: 13: /usr/scripts/jup.sh: pipenv: not found

Current Script:

. /etc/profile

#exec &> /home/john/logfile2.txt

echo 'running jup.sh' >> /home/john/logfile2.txt

cd /home/john/jup
echo $PWD >> /home/john/logfile2.txt

/usr/local/bin/pipenv run jupyter notebook &

juypter is an IDE for code exploration. jupyter.org. I installed it via instructions here: https://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html

Root: I've run it both in sudo crontab and regular crontab. Prior to the last couple of days it has not been run as root. As part of troubleshooting, I've run the script in both, to see it makes a difference. It has not.

New contributor
alkelaun is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Welcome to AskUbuntu! Please also take the tour to learn how this community works, and read How to Ask for what's expected from you when you ask questions. Not that there's that much wrong with this one :-) – Murphy Jun 13 at 0:10
  • 1
    Please edit your question and show us the current crontab using the full path to pipenv. Try adding ` 2> /tmp/logfile` at the end and then rebooting. Check that /tmp/logfile is created and see what the contents are. What is jupyter? Does that also need a full path? Is it some module you've installed and, if so, will root have access to it? Why are you running this as root? – terdon Jun 13 at 8:11
  • Please also add the verbatim content of that email, so we can see what exactly it says. – Murphy Jun 13 at 11:56
  • Perhaps this provides some hints that help you with that issue: stackoverflow.com/questions/46391721/pipenv-command-not-found – Murphy Jun 14 at 11:32

When scripts are executed by cron, usually the environment variables aren't set as you're used to from a login shell. Especially PATH is missing, which means the shell can't find the pipenv command. Possible solutions:

  1. Add the absolute path to external commands. You can find the location of pipenv with

    $ which pipenv

    In the end that call in your script should read something like

    /usr/bin/pipenv run jupyter notebook &
  2. Load the complete environment. This is usually achieved by adding the following line to the top of your script:

    . /etc/profile
  • 1
    @terdon @Murphy, I implemented both and it still won't run. The first solution was part of my problem. I deleted the exec &> /home/user/logfile2.txt line, and I received local mail indicating pipenv couldn't be found. – alkelaun Jun 13 at 1:05

Your Answer

alkelaun is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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