-
Notifications
You must be signed in to change notification settings - Fork 14
/
run-one.1
79 lines (51 loc) · 3.07 KB
/
run-one.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
.TH run\-one 1 "9 Jan 2011" run\-one "run\-one"
.SH NAME
run\-one \- run just one instance at a time of some command and unique set of arguments (useful for cronjobs, eg)
.SH SYNOPSIS
\fBrun\-one\fP COMMAND [ARGS]
\fBrun\-this\-one\fP COMMAND [ARGS]
\fBrun\-one\-constantly\fP COMMAND [ARGS]
\fBkeep\-one\-running\fP COMMAND [ARGS]
\fBrun\-one\-until\-success\fP COMMAND [ARGS]
\fBrun\-one\-until\-failure\fP COMMAND [ARGS]
.SH DESCRIPTION
\fBrun\-one\fP is a wrapper script that runs no more than one unique instance of some command with a unique set of arguments.
This is often useful with cronjobs, when you want no more than one copy running at a time.
\fBrun\-this\-one\fP is exactly like \fBrun\-one\fP, except that it will use \fBpgrep\fP(1) and \fBkill\fP(1) to find and kill any running processes owned by the user and matching the target commands and arguments. Note that \fBrun\-this\-one\fP will block while trying to kill matching processes, until all matching processes are dead.
\fBrun\-one\-constantly\fP operates exactly like \fBrun\-one\fP except that it respawns "COMMAND [ARGS]" any time COMMAND exits (zero or non-zero).
\fBkeep\-one\-running\fP is an alias for \fBrun\-one\-constantly\fP.
\fBrun\-one\-until\-success\fP operates exactly like \fBrun\-one\-constantly\fP except that it respawns "COMMAND [ARGS]" until COMMAND exits successfully (ie, exits zero).
\fBrun\-one\-until\-failure\fP operates exactly like \fBrun\-one\-constantly\fP except that it respawns "COMMAND [ARGS]" until COMMAND exits with failure (ie, exits non-zero).
.SH EXAMPLE
In one shell:
$ run\-one rsync -azP $HOME [email protected]:/srv/backup
foouser/
foouser/.bash_history
40298 100% 37.13MB/s 0:00:00 (xfer#1, to-check=3509/3516)
foouser/.viminfo
20352 100% 98.39kB/s 0:00:00 (xfer#3, to-check=3478/3516)
...
sent 746228 bytes received 413059 bytes 36802.76 bytes/sec
total size is 3732890955 speedup is 3219.99
In another shell, while the first is still running:
$ run\-one rsync -azP $HOME [email protected]:/srv/backup
$ echo $?
1
Another example... In one shell:
$ run\-one top
In another shell:
$ run\-one top
$ echo $?
1
$ run\-this\-one top
top \- 17:15:36 up 1:43, 3 users, load average: 1.05, 1.04, 1.00
Tasks: 170 total, 1 running, 169 sleeping, 0 stopped, 0 zombie
...
And note that the process in the first shell was killed.
You might want to keep one ssh connection up and running all the time, with:
$ run-one-constantly ssh -N -C -L 3128:localhost:3128 -L 7778:localhost:7778 example.com &
.SH SEE ALSO
\fBflock\fP(1), \fBkill\fP(1), \fBpgrep\fP(1)
.SH AUTHOR
This manpage and the utility was written by Dustin Kirkland <[email protected]> for Ubuntu systems (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 3 published by the Free Software Foundation.
On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL, or on the web at \fIhttp://www.gnu.org/licenses/gpl.txt\fP.