What is Termbot? #
Termbot is a versatile command-line tool designed to facilitate seamless interactions with OpenAI’s GPT models (For now, only) directly from your terminal. Whether it’s analyzing log files, generating reports from network scans, or summarizing git diffs, Termbot leverages the power of GPT and the Linux interface to transform and process text-based data efficiently. With customizable contexts (Prompts), it adapts to varied use cases, making it a powerful assistant and excellent for automation.
Practical use cases #
Setup & “good to know” #
- Aliasing is great for quick use of Termbot:
alias t='termbot'
Prompting #
- The most basic prompt method:
t -p "Why is Amsterdam called that way?"
- Including commands in our prompt:
Take, for example, using pdfly to extract text from a PDF and analyzing it with Termbot
t -p "Create a Summary: $(pdfly extract-text some_document.pdf)"
Or even quick shell scripting:
t -p "Create a bash one-liner to find .log files >10MB: $(pwd)"
Piping and/or redirecting #
This is my favorite way of using Termbot.
Simply, and directly, having a prompt written in our current working directory, called prompt.md:
t < prompt.md
Combining piping with context and prompting:
sudo nmap -A 22 192.168.1.152 | t -p "Generate a report about the nmap scan results by using the provided example template" -c nmap_scan_report_template.md
Redirecting stdout to Termbot with < operator:
t -p "Make a children story that is based on Go's Proverbs" < $(pdfly extract-text "Go Proverbs.pdf")
Simply piping any output to termbot:
tail -f /var/log/nginx/access.log | t -p "Identify any unusual access patterns or potential security threats in these Nginx logs."
git diff | t -p "Provide a concise summary of the changes in this git diff and suggest a commit message."
SysAdmin/DevOps Automation #
[!WARNING] Termbot uses OpenAI’s GPT (For now) so be cautious what you use it for and what data you send to OAI
- System health analysis automation
We can even make wrapper functions with cronjobs that would do things ike:
(`log_ctx` would be a file with example output, specific instructions, etc.)
log_doctor() {
tail -n "${2:-50}" "$1" | termbot -c log_ctx \
-p "Here are recent log entries: $(cat -)"
}
Make it usable with chmod + x,
Cronjob for reading the last 50 lines of Syslog and redirect termbot’s output to a specific log file:
30 2 * * 0 /usr/local/bin/log_doctor /var/log/syslog 50 >> ~/logs/log_doctor.log 2>&1
- Error analysis automation
Having the following function, that extracts errors from a specific service (As specified with argument $1):
incident_suggester() {
local errs
errs="$(journalctl -u "$1" -p err -n "${2:-100}" --no-pager)"
local ai=$(echo -e "Error excerpt:\n$errs" |
termbot -c incident_ctx \
-p "Analyze and suggest fix" )
echo "$ai"
}
And using Cron for it:
@hourly incident_remediate $MY_SERVICE | tee /var/log/incident.log
Context files // Prompt Library #
Under $HOME/.config/termbot/context/, we can have a prepared prompt library, so we can pass them to termbot. They can be a role or persona for Termbot, lengthy prompts, or even example outputs
For the sake of brevity of this post, we have this very small file called chain_context:
1. Read input.
2. Identify key topics.
3. Analyze each topic.
4. Conclude with recommendations.
We can use it directly with Termbot (-c or --context flag):
# Verify Termbot's context file exists in $HOME/.config/termbot/context/:
t -l
t -c chain_context -p "$(cat strategic_plan.txt)"
Those are the use cases people have shared with me and some that I have used, and there may be a lot more hacky implementations we haven’t even thought of.