...
 
Commits (5)
......@@ -175,14 +175,14 @@ class BaseRunner(metaclass=BaseRunnerMeta):
if f:
os.makedirs(os.path.dirname(f), exist_ok=True)
returncode, stdout, stderr = self.run_command(command, use_shell,
returncode, stdout, stderr = self.run_command(command, euid, use_shell,
job_id)
self._check_and_write(stdout_file, euid, run_at, job_id, command,
returncode, stdout, is_stdout=True)
self._check_and_write(stderr_file, euid, run_at, job_id, command,
returncode, stderr)
def run_command(self, command, use_shell, job_id):
def run_command(self, command, euid, use_shell, job_id):
'''Runs a command, and returns (exit_status, STDOUT, STDERR) tuple.'''
try:
command_ = command if use_shell else shlex.split(command)
......@@ -190,7 +190,8 @@ class BaseRunner(metaclass=BaseRunnerMeta):
command_,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=use_shell
shell=use_shell,
preexec_fn=lambda: os.seteuid(int(euid)) # Setting EUID
)
except Exception as err:
# Setting `returncode` to 127
......
......@@ -31,6 +31,9 @@ mkdir -p /var/log/hatd/
# Copying the logrotate file
cp system/hat-daemon /etc/logrotate.d/
# Copying and gzip-ing man page
gzip --to-stdout system/hatc.1 >/usr/share/man/man1/hatc.1.gz
# Create `hatd` group and set SETGID on `/var/run/hatd/locks/`
addgroup hatd
mkdir -p /var/run/hatd/locks
......@@ -59,7 +62,7 @@ systemctl enable hat-daemon.service && \
# rm /etc/systemd/system/hat-daemon.service && \
# systemctl daemon-reload
# 2. Remove other files and directories:
# rm -r /var/lib/hatd/ /var/run/hatd/ /usr/lib/hatd/ /etc/logrotate.d/hat-daemon
# rm -r /var/lib/hatd/ /var/run/hatd/ /usr/lib/hatd/ /etc/logrotate.d/hat-daemon /usr/share/man/man1/hatc.1.gz
#
# N.B: If you want to keep the enqueued jobs, don't remove `/var/lib/hatd/`, precisely `/var/lib/hatd/hatdb.pkl`.
#
.\" Man page of hatc -- The hatd client
.TH HATC 1 "25 February, 2018" "HAT (Hyper-AT)"
.SH NAME
hatc \- queue, modify, remove jobs/tasks for executing at a later time
.SH SYNOPSIS
.B hatc
.RB -V
.br
.B hatc
.RB -l
.br
.B hatc
.RB -c
.br
.B hatc
.RB -a
.RI [ -e ]
.IR command
.IR datetime
.RI [ shell ]
.br
.B hatc
.RB -m
.RI [ -e ]
.IR job-ID
.RI [ command ]
.RI [ datetime ]
.RI [ shell ]
.br
.B hatc
.RB -r
.IR job-ID
.RI [ job-ID... ]
.br
.SH DESCRIPTION
.B HAT (Hyper-AT)
is an one time run job scheduler, with an emphasis on usability.
It is designed to be a direct replacement of all one time run task
scheduling engines/toolsets, with a much better, usable interface
and enhanced features.
.B hatc
is the userspace tool to communicate with
.B hatd
-- the daemon.
.TP 8
Some of the features of \fBhatc\fR:
.br
.IR 1.
Time resolution of seconds i.e. it is possible to run jobs at the mentioned second
.br
.IR 2.
Run job on the shell of choice; no binding to `/bin/sh`
.br
.IR 3.
Job modification is supported; one can easily modify command, time of an enqueued job
.br
.IR 4.
Flexible datetime specifications, see \fBDATETIME SPEC\fR section below
.br
.IR 5.
Will run a scheduled job later when the computer was off at that time, so no job will be missed. Also see point 6
.br
.IR 6.
Option for running a job at the specified time only e.g. if the computer was off at that time, job will not be run
.br
.IR 7.
User specific jobs, no user can see other users' jobs
.br
.IR 8.
- User based logging, all logs from jobs of a user go in `~/.hatd/logs/`
.br
.IR 9.
Easy to use
.br
.PP
.SH OPTIONS
.TP 8
\fB\-V\fR, \fB\-\-version\fR
print the version number to standard error and exit.
.TP
\fB\-h\fR, \fB\-\-help\fR
show this help message and exit.
.TP
\fB\-l\fR, \fB\-\-list\fR
show the list of queued jobs.
.TP
\fB\-c\fR, \fB\-\-count\fR
show the number of queued jobs.
.TP
\fB\-e\fR, \fB\-\-exact\fR
run the job only at the time specified, not after. By default, a job is will be run
later if e.g. the computer was off at the desired run time.
.TP
\fB\-a\fR command datetime [shell], \fB\-\-add\fR command datetime [shell]
Add a new job. If \fBshell\fR is specified, the job will be run in the given shell,
otherwise no shell will be used.
.br
See \fBDATETIME SPEC\fR below for datetime specifications. Also, check out the \fBEXAMPLES\fR
section.
.TP
\fB\-m\fR job-ID [command] [datetime] [shell], \fB\-\-modify\fR job-ID [command] [datetime] [shell]
Modify an enqueued job. The first argument must be the job ID (from \fBhatc -l\fR).
.br
`_` can be used as a placeholder for using an already saved value for an argument
(except \fBjob-ID\fR).
.br
If \fBshell\fR is used, \fBcommand\fR must be specified explicitly,
and vice versa. The \fB-e\fR/\fB--exact\fR argument must be specified explicitly too.
.br
See \fBDATETIME SPEC\fR below for datetime specifications. Also, check out the \fBEXAMPLES\fR
section.
.TP
\fB\-r\fR job-ID [job-ID ...], \fB\-\-remove\fR job-ID [job-ID ...]
Remove enqueued job(s) by Job ID. For removing multiple jobs, separate job-IDs by space.
.br
Check out the \fBEXAMPLES\fR section below.
.SH DATETIME SPEC
\fBhatc\fR supports fairly advanced datetime specifications. For a detail spec, please see
.IR https://github.com/heemayl/humantime-epoch-converter
.TP
Here are a few example specs:
.br
yesterday
.br
today at 6:50
.br
tomorrow 16:40 + 2 hr
.br
next sunday 23
.br
next tuesday at 21:22:32
.br
next wed at 2:30 + 48min 21secs
.br
now
.br
now + 1 hr 2 min 3 sec
.br
now+32hr2m30s
.br
tomorrow 9 - 1hour30min21s
.br
now+21h30m
.br
.SH EXAMPLES
.TP
\fBListing and counting jobs:\fR
.br
hatc \fB# List scheduled jobs\fR
.br
hatc -l \fB# List scheduled jobs\fR
.br
hatc -c \fB# Number of jobs scheduled\fR
.TP
\fBAdding jobs:\fR
.br
hatc --add 'free -m' 'now + 30 min' \fB# Scheduling `free -m` to run after 30 minutes from now\fR
.br
hatc --add 'free -g' 'now+1h40m30s' \fB# `free -g` will run after 1 hour, 40 minutes, 30 seconds from now\fR
.br
hatc -a 'tail -10 /var/log/syslog' 'tomorrow at 14:30' \fB# `tail -10 /var/log/syslog` is scheduled to be run the next day at 02:20 PM\fR
.br
hatc -a 'func() { echo Test ;}; func()' 'next sunday 11' bash \fB# The function `func` will be run on `bash` at next sunday 11:00 AM\fR
.br
hatc -a 'echo $PATH' 'today 18:06:34' dash \fB# `echo $PATH` will be run on shell `dash`, today at 6:06:34 PM\fR
.br
hatc -a date 'tomorrow 10 - 6 hr 12 min 3 sec' \fB# `date` will be run at the time resulting from the subtraction\fR
.br
hatc -e -a 'free -g' 'now+1h' sh \fB# Making the job exact, see `-e`/`--exact` option\fR
.TP
\fBModifying jobs:\fR
.br
hatc --modify 2 'free -g' 'now + 30 min' \fB# Everything is updated for Job with ID 2\fR
.br
hatc -m 31 _ 'tomorrow at 14:30' \fB# The command is kept as original, only time is updated\fR
.br
hatc -m 4 'func() { echo Test ;}; func()' _ \fB# Only command is updated\fR
.br
hatc -m 23 'echo $PATH' 'today 18:06:34' dash \fB# Everything is updated\fR
.br
hatc --modify 78 _ 'tomorrow 10 - 6 hr 12 min 3 sec' \fB# Only time is updated\fR
.br
hatc --exact -m 2 _ _ \fB# Making the job to run at exact time, not anytime after; keeping command/time specifications as-is\fR
.br
hatc -m 2 _ _ \fB# Removing the exact option from the previous job, by not using `-e` or `--exact` option\fR
.TP
\fBRemoving jobs:\fR
.br
hatc --remove 12 \fB# Removing job with Job ID 12\fR
.br
hatc -r 3 8 23 \fB# Removing 3 jobs having IDs 3, 8, 23\fR
.br
hatc -r 2 15 \fB# Removing 2 jobs having IDs 2, 15\fR
.SH FILES
.I ~/.hatd/
.br
.I /var/lib/hatd/
.br
.I /var/run/hatd/
.br
.I /usr/lib/hatd
.SH BUGS
There could be bugs. Please report bugs to https://github.com/heemayl/hat/
.SH AUTHOR
Originally written by Readul Hasan Chayan (Heemayl) <[email protected]>.