guest-tools/osmike-cron
2026-11-10 14:09:24 +01:00

15 lines
981 B
Python
Executable File

#!/usr/bin/env python3
"""Guest-only wake-time jobs. Due jobs run when your guest is awake; never wakes the host or uses fleet scheduler."""
import argparse,json,os,secrets,time
from pathlib import Path
p=argparse.ArgumentParser(); sub=p.add_subparsers(dest='action',required=True); add=sub.add_parser('add'); add.add_argument('--after',type=int,required=True,help='seconds'); add.add_argument('command',nargs='+'); sub.add_parser('list'); rm=sub.add_parser('remove'); rm.add_argument('id'); a=p.parse_args()
d=Path('/data/guest-jobs'); d.mkdir(mode=0o700,exist_ok=True)
if a.action=='add':
if a.after<1: p.error('after must be positive')
ident=secrets.token_hex(8); f=d/(ident+'.json'); f.write_text(json.dumps({'due':time.time()+a.after,'command':a.command})); print(ident)
elif a.action=='list':
for f in d.glob('*.json'): print(f.stem,f.read_text())
else:
if not all(c in '0123456789abcdef' for c in a.id): p.error('invalid id')
(d/(a.id+'.json')).unlink(missing_ok=True)