Use SageMaker Lifecycle configuration to execute a jupyter notebook on start

I want to set up some automatic schedule for running my SageMaker Notebook.
Currently I found link like this:

I followed the steps to set up the lamda, cloudwatch, and the Lifecycle configuration.
During different experiment, some times the on_start lifecycle configuration can execute the jupyter notebook (In the notebook i just install some package and load the package and save the loading status to S3 bucket). However, it failed due to it can't stop the notebook.

Then I added permission to my IAM role for SageMaker autostop. Now the notebook instance can be turn on and turn off. But I don't see anything uploaded to my S3 any more. I am wondering if the on_start started the auto-stop too early before it finish the steps?

Below is my script for the current lifecycle configuration

set -e

NOTEBOOK_FILE="/home/ec2-user/SageMaker/Test Notebook.ipynb"

source /home/ec2-user/anaconda3/bin/activate "$ENVIRONMENT"

nohup jupyter nbconvert --ExecutePreprocessor.timeout=-1 --ExecutePreprocessor.kernel_name=python3 --execute "$NOTEBOOK_FILE" &

echo "Finishing running the jupyter notebook"

source /home/ec2-user/anaconda3/bin/deactivate

IDLE_TIME=60  # 1 minute

echo "Fetching the autostop script"
wget -O

echo "Starting the SageMaker autostop script in cron"
(crontab -l 2>/dev/null; echo "*/1 * * * * /bin/bash -c '/usr/bin/python3 $DIR/ --time ${IDLE_TIME} | tee -a /home/ec2-user/SageMaker/auto-stop-idle.log'") | crontab -

Note that, I do see the echo "Finishing running the jupyter notebook" from the cloudwatch log. But that's usually the first thing i saw from the log and it shows up immediately - faster than I expect how long it should take.

Also, currently the notebook is only running some fake task. The real task may take more than an hour.

Any suggestions help! Thank you for taking the time to read my questions.