simple CLI utility to run other programs periodically as daemon without cron
Project description
Daemon Loop
Daemon loop is simple and clean CLI utility to run programs periodically.
It's better alternative to running commands like:
while true; do date >> date.log; sleep 5; done
(or even running such commands in screen/tmux sessions)
Installation
pip3 install daemon-loop
Usage
usage: loop [-h] [-n N] [-p PERIOD] [--log FILENAME] [--err] [-v] [-d]
command [command ...]
Run command in loop (with features)
positional arguments:
command command (maybe in quotes, e.g "ls -l")
optional arguments:
-h, --help show this help message and exit
-n N Run N times and exit (default: 0 = infinite)
-p PERIOD, --period PERIOD
Run every N seconds (default: 60)
--log FILENAME Write command stdout to this file
-e, --err Write command stderr to logfile)
-v, --verbose Write loop technical info to logfile)
-d, --daemon Work as daemon
Example usage
Simple and almost useless - run date
every second until Ctrl-C:
$ loop date
Sun Dec 20 05:18:21 +07 2020
Sun Dec 20 05:19:21 +07 2020
Sun Dec 20 05:20:21 +07 2020
^C
Run date +%s
(print unixtime) 3 times every 10 seconds and quit
$ loop -p 10 -n 3 -- date +%s
1608416485
1608416495
1608416505
And now something more useful - make our date
program a daemon!
$ loop -d -v -p 10 --log /tmp/x.log --err -- date +%s
$ pidof -x loop
24684
-d
: run as daemon-p
: period is 10 seconds--log
: logfile--err
: include stderr to logfile-v
: include technical info about time of start/stop, status code and daemon pid
log file will look like this:
# 2020-12-20 05:32:52 my pid: 25464 run: date +%s
1608417172
# 2020-12-20 05:32:52 finished with status 0
# 2020-12-20 05:33:02 my pid: 25464 run: date +%s
1608417182
# 2020-12-20 05:33:02 finished with status 0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file daemon_loop-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: daemon_loop-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db6ea07abe3c5abcaaca2f3133ca4231249bc5aa243d9d0e1bbbff52b9c7e05d |
|
MD5 | 928c1e1eb74a1a0fd9bd81657cbcdcce |
|
BLAKE2b-256 | f37c286c25cbdbd919516405b0e0457a07e3850c40a827aed2eabc199439ef11 |