@@ -80,6 +80,11 @@ function __is_valid_reaper_timeout ()
80
80
__is_valid_positive_integer " ${@ } "
81
81
}
82
82
83
+ function __is_valid_wall_timeout ()
84
+ {
85
+ __is_valid_positive_integer " ${@ } "
86
+ }
87
+
83
88
function __reap ()
84
89
{
85
90
kill \
@@ -109,6 +114,10 @@ function __usage ()
109
114
If not specified the default is SIGTERM.
110
115
-v, --verbose Output informational messages.
111
116
If not specified the default is quiet.
117
+ -w, --wall MESSAGE Set a wall message to send before session end.
118
+ -T, --wall-timeout SECONDS Set the time before session end to send the
119
+ wall message. The default is 30 seconds.
120
+ Set to 0 to disable sending a wall message.
112
121
EOF
113
122
exit 1
114
123
}
@@ -129,7 +138,8 @@ function main ()
129
138
local session_end
130
139
local state_value
131
140
local verbose=" false"
132
- local warning_timeout=" 30"
141
+ local wall_message
142
+ local wall_timeout=" 30"
133
143
134
144
while [[ " ${# } " -gt 0 ]]
135
145
do
@@ -165,6 +175,22 @@ function main ()
165
175
verbose=" true"
166
176
shift 1
167
177
;;
178
+ -w|--wall)
179
+ wall_message=" ${2} "
180
+ shift 2 || break
181
+ ;;
182
+ --wall=* )
183
+ wall_message=" ${1#* =} "
184
+ shift 1
185
+ ;;
186
+ --wall-timeout)
187
+ wall_timeout=" ${2} "
188
+ shift 2 || break
189
+ ;;
190
+ --wall-timeout=* )
191
+ wall_timeout=" ${1#* =} "
192
+ shift 1
193
+ ;;
168
194
* )
169
195
>&2 printf -- \
170
196
' ERROR: Unknown option %s\n' \
@@ -230,14 +256,22 @@ function main ()
230
256
EXIT INT TERM
231
257
__create_lock
232
258
259
+ if ! __is_valid_wall_timeout " ${wall_timeout} "
260
+ then
261
+ >&2 printf -- \
262
+ ' ERROR: Invalid --wall-timeout\n' \
263
+ __usage
264
+ fi
265
+
233
266
if (( timeout > 0 ))
234
267
then
235
268
trap __reap \
236
269
EXIT INT TERM
237
270
238
- if (( timeout <= warning_timeout ))
271
+ if [[ -z ${wall_message} ]] \
272
+ || (( timeout <= wall_timeout ))
239
273
then
240
- warning_timeout =" 0"
274
+ wall_timeout =" 0"
241
275
fi
242
276
243
277
session_start=" $(
@@ -246,20 +280,18 @@ function main ()
246
280
247
281
__create_state
248
282
249
- if coproc read -t " $(( ${timeout} - ${warning_timeout } )) "
283
+ if coproc read -t " $(( ${timeout} - ${wall_timeout } )) "
250
284
then
251
285
wait " ${! } " || :
252
286
253
- if (( warning_timeout > 0 ))
287
+ if (( wall_timeout > 0 ))
254
288
then
255
- wall " Session expires in ${warning_timeout} seconds. " || :
289
+ wall " ${wall_message} " || :
256
290
257
- if coproc read -t " ${warning_timeout } "
291
+ if coproc read -t " ${wall_timeout } "
258
292
then
259
293
wait " ${! } " || :
260
294
fi
261
- else
262
- wall " Session expired." || :
263
295
fi
264
296
fi
265
297
0 commit comments