Expand my Community achievements bar.

Adobe Summit 2025: AEM Session Recordings Are Live! Missed a session or want to revisit your favorites? Watch the latest recordings now.

AIO CLI Download logs not working when run as scheduled task/cron job

Avatar

Level 1

Hi All,

We are using AEM as Cloud Service, for log analysis I am trying to set up AIO CLI to download logs on daily basis and poll.

I am able to download the logs but when I run it as scheduled job, its not working I do not see any error. Any pointers will be greate.

 

Thanks,

Sunny.  

2 Replies

Avatar

Community Advisor

Hi @sunny_gvp,

IMO, the issue could be because of: 

Authentication Token / Session Not Available

AIO CLI relies on a locally cached access token or interactive login, which may not persist or be accessible in headless environments like cron.

Solution:

  • Use Service Account JWT or OAuth integration (via Adobe I/O Console) to authenticate non-interactively.

  • Configure aio config:set or use AIO_CLI_AUTH related env variables to set credentials for headless use.

Adobe guide: Using AIO CLI with Service Credentials

Working Directory or File Access

If your cron job runs in a different directory, relative paths (e.g., for saving logs) might fail silently.

Solution:

  • Use absolute paths for saving downloaded logs.

  • Add logging to your script (e.g., >> /var/log/aio-download.log) to capture output/errors.

References:

Hope that helps!


Santosh Sai

AEM BlogsLinkedIn


Avatar

Community Advisor

Hi @sunny_gvp ,

The issue occurs because cron environments lack interactive authentication and proper path/context. Here's exactly how to fix it.

1. Use a Service Account for Headless Authentication

The AIO CLI by default uses an interactive login (aio auth login) that doesn't persist for cron/scheduled jobs.

Instead, use Service Credentials (JWT or OAuth).

Steps:

  - Go to Adobe Developer Console.

  - Create or access your project > add Cloud Manager API.

  - Add Service Account (JWT) credentials.

  - Download the config.json with credentials.

  Authenticate via AIO CLI (one-time setup):

aio auth:jwt:login --client-id <CLIENT_ID> --client-secret <CLIENT_SECRET> --technical-account-id <TECH_ID> --org-id <ORG_ID> --private-key-path /absolute/path/to/private.key --meta-scopes ent_cloudmgr_sdk

You can now use this service account in scripts without requiring manual login.

2. Set Required ENV Variables for Cron

Export required variables in your cron script:

export AIO_CLI_AUTH_CONTEXT=your-context
export AIO_CLI_CONFIG_DIR=/absolute/path/to/.aio

This ensures cron knows where to find your AIO auth context.

3. Use Absolute Paths in Cron

Avoid relative paths. Your script should use absolute paths to avoid failures like:

aio cloudmanager:logs:list <params> > /var/log/aio/log-download.log 2>&1

4. Add Logging in Your Cron Script

Wrap your command in a shell script (e.g., aio-download.sh) with logging:

#!/bin/bash
export AIO_CLI_AUTH_CONTEXT=your-context
export AIO_CLI_CONFIG_DIR=/home/ubuntu/.aio

/usr/local/bin/aio cloudmanager:logs:download --programId <PID> --environmentId <EID> --service author --logname access.log --output /home/ubuntu/logs >> /home/ubuntu/logs/aio-download.log 2>&1

And add this to cron:

0 3 * * * /home/ubuntu/aio-download.sh

5. Ensure AIO CLI and Node Are in Cron’s PATH

Sometimes cron doesn't inherit your full shell environment.

Add this at the top of your script:

export PATH=/usr/local/bin:/usr/bin:/bin

 

Regards,
Amit