A practical example that updates a Libre Office spreadsheet, analyzes storage usage, and sends the result automatically.
If you are starting out with Agents and want to automate boring stuff or need some inspiration on how to do simple cronjobs with codex or other harnesses, Here’s my approach with super simple ZSH Wrappers. I usually use this method for a lot of things like finance spreadsheets, dividend calendars, networth report, news, IT security news and CVE news, stock market news and more.
UPDATING EXCEL SHEETS with CODEX
I picked this example because it is one of the most simple ones.
I use Codex to update my NAS Storage Report Excel Sheet, check the current used space and then send me a report and the updated Libreoffice file via Whatsapp. Whatsapp / WAHA is just an example here, you can substitute it with whatever method you would like to get notified.
prerequisites:
- A Linux machine with running cron
- Codex CLI and an openAI account
- A method to send yourself messages or mails from the command line
THE SHELL SCRIPT WRAPPER
This is the Shell Script Wrapper around the codex call. It prepares all the necessary files, executes the command to check the disk space, attaches it to the prompt file, calls codex with the prompt markdown file and then copies the result and sends the output and file via Whatsapp to me.
I removed all my custom error handling for the case of simplicity because my error handling is a custom solution which would just require a lot more documentation. For the sake of keeping the example easy to understand we just ignore most error handling now.
#!/usr/bin/zsh
MD_FILE="datahoarding_excel.md"
ORIGINAL_DOCUMENT="$HOME/Documents/DATAHOARDING.STATS.ods"
DATA_DIR="$HOME/GIT/CODEX_WORKING_DIR/Datahoarding"
NEW_DOCUMENT="$DATA_DIR/DATAHOARDING.STATS_updated.ods"
cp "$ORIGINAL_DOCUMENT" "$DATA_DIR/DATAHOARDING.STATS.ods"
SCRIPT_DIR="${${(%):-%x}:A:h}"
cd "$SCRIPT_DIR"
MD_FILE_PATH="${SCRIPT_DIR}/${MD_FILE}"
MD_FILE_WITH_DF="datahoarding_excel_with_DF.md"
DF_OUTPUT=$(df -h /mnt/ORILLA)
rm -f ${MD_FILE_WITH_DF}
touch ${MD_FILE_WITH_DF}
cat ${MD_FILE_PATH} >> ${MD_FILE_WITH_DF}
printf '%s\n' "$DF_OUTPUT" >> ${MD_FILE_WITH_DF}
OUTPUT=$(codex exec --full-auto - < "$MD_FILE_WITH_DF")
retcode=$?
if (( retcode != 0 )); then
echo "codex_exec_file failed with exit code $retcode"
exit 1
fi
if [[ ! -s "$NEW_DOCUMENT" ]]; then
echo "Updated spreadsheet was not created"
exit 1
fi
waha_automation_send_message_to_me "$OUTPUT"
rm -f "$MD_FILE_WITH_DF"
cp "$NEW_DOCUMENT" "$ORIGINAL_DOCUMENT"
waha_automation_send_ods_to_me "$NEW_DOCUMENT"
echo "[DATAHOARDING REPORT] updated Excel Sheet and copied to documents"
THE PROMPT FILE
This is the datahoarding_excel.md Markdown file that gets used in the wrapper above and gets directly blasted into codex.
DATA HOARDING MONTHLY UPDATE
In the CODEX_WORKING_DIR there is a sub-directory called Datahoarding.
There you can find the current file DATAHOARDING.STATS.ods.
I will attach the latest numbers,
please update the STORAGE_USAGE Sheet in the ODS File accordingly
with the numbers of the current month.
Add Year / Months if it is necessary exactly like the previous entries.
Use them as template how it should look.
Save the file as DATAHOARDING.STATS_updated.ods in the same folder and
give me a Datahoarding report with the current numbers,
the trend, the trajectory and if I am running out of space soon.
And in the report please print the numbers nicely formatted,
so they are eyecandy if it gets posted via a Whatsapp Bot.
Maybe use some nice Emojies.
To avoid displacement rather use new lines instead of tabs
If the excel sheet already has all the numbers for the current
month you can just copy the original to DATAHOARDING.STATS_updated.ods
keep it brief.
IMPORTANT: Report only as Output. I don't want it in the Excel sheet
Begin the Message with:
🖴 DATA HOARDING MONTHLY REPORT
Here are the latest numbers:
Note: the latest numbers at the end just simply get attached to the file in the shellscript above with a custom df -h command
THE CRONJOB
Last but not least. We add it to the Linux crontab and let it execute once a month
30 5 1 * * ~/CODEX/datahoarding_excel.sh
That’s it. Super simple, Super basic but super effective. You can transfer this concept to all kinds of things you want to automate. I no longer update Excel Sheets manually. Of course Finance stuff have a bit more complex prompts and I have scripts that do a million additional things but the basic concept is always the same: Wrapper prepares files, Codex does the job, output gets checked and sent via Whatsapp message.