Automation with Cron Jobs and Variables¶
Overview¶
The RosettaHub CLI is designed for automation. Variables let you store and reference values across commands, cron jobs schedule recurring tasks, and startup scripts initialize machines on boot. In this tutorial you will set up variables, create scheduled jobs, and build shell scripts that leverage the CLI.
Prerequisites¶
- [ ] Completed Getting Started with the CLI
- [ ] At least one formation available
Steps¶
Step 1: Work with Variables¶
Variables store reusable values that can be referenced in commands.
Set a variable:
Get a variable value:
List all variables:
List variable keys:
Delete a variable:
Step 2: Save Command Results to Variables¶
Many list commands support the -v / --set flag to save results to a variable:
You can then retrieve the stored value:
Step 3: Use Variable Fields¶
Access specific fields from stored variables:
Save variable data to a file:
Step 4: Create a Cron Job¶
Schedule a recurring task:
List scheduled jobs:
Delete a cron job:
Step 5: Create Startup Scripts¶
Startup scripts run automatically when a machine boots:
List startup scripts:
Step 6: Use --quiet and --yes for Non-Interactive Scripts¶
When using the CLI in shell scripts, suppress prompts and extra output:
--quiet(-q) suppresses informational messages--yes(-y) auto-confirms destructive operations
Step 7: Use JSON Output for Scripting¶
Set JSON as the default output for programmatic use:
Or override per command:
rh formation ls -O json | jq '.[].formationUid'
rh session ls -O json | jq '[.[] | select(.status == "running")]'
rh image ls -O json | jq 'length'
Step 8: Build a Deployment Script¶
Combine CLI commands into a deployment workflow:
#!/bin/bash
set -e
IMAGE_UID="your-image-uid"
KEY_UID="your-key-uid"
LABEL="Deploy-$(date +%Y%m%d)"
echo "Launching formation..."
rh image launch "$IMAGE_UID" \
-l "$LABEL" \
-k "$KEY_UID" \
-g -q -y
echo "Formation is running."
rh session ls
Step 9: Use --dry-run for Safety¶
Preview any operation without executing:
rh formation delete <formationUid> --dry-run
rh compliance execute --portfolio-uid <uid> --cloud-account-uid <uid> --dry-run
Warning
Always test batch scripts with --dry-run first to preview what will happen.
Next Steps¶
- Compliance and Cloud Custodian — automate compliance scans
- Containers and Kubernetes — manage containerized workloads
Troubleshooting¶
Variable not found
Variable names are case-sensitive. Check with rh var keys.
Script hangs waiting for input
Add --yes to skip confirmation prompts and --quiet to suppress interactive output.
How do I run the CLI without the daemon?
The RosettaHub daemon must be running for all CLI commands. Ensure it is started before running scripts.