How to run a script every morning, laptop closed
Tell the agent what to do and when. It runs on its own computer at that time, even if your laptop is shut and the computer is asleep.
Some jobs are small and boring: fetch the weather, check a price, copy a file, count the rows in a table. You can do each one by hand in a minute. The trouble is doing it every day.
The Schedules page in awx runs a prompt for you at a time you choose. This post sets up a morning report, then follows what happened when it ran.
Make a schedule
Open Schedules and press New schedule. The form asks for:
- Name. We used "Morning report".
- Computer. The one the job runs on. We chose a Small computer, because a script needs no desktop.
- Prompt. What the agent should do each time. Write it as you would in a chat.
- When. Every day at a time (you can choose the days), every so often (every few minutes, hours or days), or once.
- Time zone. It starts as Asia/Kuala_Lumpur. The computer's own clock is UTC, but the schedule uses the time zone you set here.
- Model and Ask me before. The same two choices as in a chat.
This is the prompt we wrote:
Make a morning report. In /home/agent/morning, keep a Python
script report.py that gets today's weather for Kuala Terengganu
from the Open-Meteo API (no key needed) and the MYR to USD
exchange rate from the Frankfurter API. Run it, save the result
to report-YYYY-MM-DD.txt in the same folder, and reply with the
report in two lines.
A note at the bottom of the form matters: nobody is watching a scheduled run, so a step that needs your approval waits for you, and you get a notice. The computer is started if it is asleep, unless you turned off auto start for it.
Run it now
After you press Create schedule, the job appears in a list with its time and its next run. Ours said every day at 08:00 (Asia/Kuala_Lumpur) and a next run of 8:00 the next morning.
You do not have to wait until morning to see if it works. Run now starts the job straight away. We pressed it while the computer was stopped, so this tested the part you cannot watch at 8 a.m.: waking a sleeping computer and running the job with nobody there.
The computer woke by itself, the agent wrote the script, ran it and replied. The whole run took about a minute.
What it wrote
Open the chat to see what happened. The agent used only Python's built-in libraries, saved the script as report.py, and saved the result in a file named for the day.
We checked the file ourselves in the terminal. It was 348 bytes, with a header, the weather line and the exchange rate:
Two things the agent noticed
These are the kind of details that make a daily report wrong without anyone telling you, so it is good that the agent said them out loud.
- The computer's clock is UTC. A report made at 8 a.m. in Malaysia would be dated the day before in UTC. The agent made the script work out Kuala Terengganu time (UTC+8) itself, so the file name and the header are right.
- The exchange rate was four days old. The Frankfurter service publishes central-bank reference rates and has none for the weekend, so it gave Friday's. A rate that looks current may not be.
The agent also offered to add the job to the computer's crontab. We did not, because the schedule already does the job, and it also starts the computer for you.
What it costs
A Small computer costs RM0.03 an hour while it runs and nothing while it sleeps. A run that wakes the computer keeps it on until it has been idle for 30 minutes, which is about 1.5 sen at most. A daily schedule is therefore about 45 sen a month at the most. Why a computer sleeps and how running time and credit work have the details.
If your credit has run out, a Free-plan computer cannot start, so the run will not happen. Keep a little credit in the account for the schedules you want to keep.
Pause, change or delete
On each job, Edit changes the prompt or the time, Pause keeps it but stops the runs, and Delete removes it. Deleting does not remove the chats it already made. We deleted ours after the test, so it would not keep running on a test account.
Cautions
- Read the script once. The agent wrote it from your prompt. Open
report.pyin the Files tab and check it does what you meant before you rely on it. - Public data can change. The two services here are free and need no key. They can change or go away, and the job would then fail without you noticing, so look at the report now and then.
- Do not put passwords or keys in a prompt. Schedule jobs that use public data, or keep secrets on the computer in a file the script reads.
- Keep your own copy of anything that matters.
awxis in early alpha.
Keep reading
- How to clean and analyse a survey CSV with pandas
- How to give the agent a job, then close your laptop
- How to turn a weather API into a web page that stays up
- Why a computer sleeps, and how to keep it running
Getting started
Sign in with your Google account, open Schedules, and press New schedule. Start with a job that uses public data, and press Run now to see it work.
Awi, signing off.