Skip to content

Nightly file uploads

The LifeOmic platform allows its users to upload files via the LifeOmic CLI. There are multiple ways to authenticate with the CLI, but for this document we’ll be using API Keys. Once an API Key is generated, the CLI can be used in conjunction with a cron job to automatically upload files each night.

API Key Creation

See the API Key Guide

Download and verify CLI

wget ""
sudo apt-get install unzip
sudo mv lo /usr/local/bin
lo --help

Setup CLI with API Key

lo setup
? Pick a LifeOmic environment: prod-us
? Specify a default LifeOmic account to use: myaccount
? Use API key for authentication? Yes
? API Key:

After pasting the API Key, you should be ready to use the CLI for file uploading. Issue the following command as a test to verify authentication is all setup:

lo projects list

Prepare local folders and PHC project

mkdir uploads
mkdir logs
lo projects create "Files Test"

Replace "Files Test" with whatever the project should be called.

Prepare upload script

Copy project ID

lo projects list
Example response:
    id:   f3a220a0-b22b-41c3-9f77-2ce7cf37c93b
    name: Files Test

Copy the ID of the project you created.

Create script


set -u
set -e
set -x

if pgrep --full "lo files upload" ; then
        echo "Already running"
        exit 0

trap "echo Process killed" SIGINT SIGTERM SIGABRT

echo `date '+%Y-%m-%d %H:%M:%S'`
cd /home/ubuntu/uploads
/usr/local/bin/lo files upload ./ f3a220a0-b22b-41c3-9f77-2ce7cf37c93b --recursive --overwrite --delete-after-upload

NOTE: In this example we’re using /home/ubuntu/uploads. You may need to change that line of the script to match the directory you’re using.

NOTE: Make sure to replace the UUID (which starts with f3a220a0-) above with your project ID.

Add execution permissions and verify a file upload

chmod +x
echo "test" > uploads/test.txt

Verify you see output similar to this:

Upload complete: test.txt, ID: `d4d9d8fc-b96b-49ad-a43c-c24f54b29941`

Also, issuing the following command should verify the uploaded file:

lo files list <projectId>

Create a cron job to execute the script

sudo mv /etc/cron.daily/
crontab -e

Add the following line (the script will run nightly at midnight) and then save:

0 0 * * * /usr/bin/timeout -s 2 172800 /etc/cron.daily/ >> /home/ubuntu/logs/lo-upload.log 2>&1

Email success or failure

Instead of sending output to the upload.log file as shown above, it can be better from a monitoring perspective to receive nightly emails upon success or failure.

Configure SMTP

You will need to configure your server to be able to send email. One tool commonly used for this purpose is postfix. For postfix installation and configuration, search the web for setup instructions specific to the type of SMTP server you’ll be using (Office 365, Gmail, and others).

Make sure to test an example email before moving on from this step:

sudo apt-get install mailutils
echo "Test email contents" | mail -s "Test email subject" ","

Reconfigure cron job to email

Update your crontab -e entry to use mail:

0 0 * * * /usr/bin/timeout -s 2 172800 /etc/cron.daily/ 2>&1 | mail -s "PHC <companyName> Files Upload" ","

Last update: 2022-02-17
Created: 2020-02-01