forked from vern/scripts
31 lines
604 B
Bash
Executable File
31 lines
604 B
Bash
Executable File
#!/usr/bin/env -S bash -e
|
|
|
|
[[ -z $1 ]] && {
|
|
printf 'Usage: %s N\nN must be a positive or zero integer\n' "$0" >&2
|
|
exit 1
|
|
}
|
|
|
|
[[ "$1" -ge 0 ]] 2> /dev/null || {
|
|
printf 'Expected non-negative integer, got `%s'\''\n' "$1" >&2
|
|
exit 2
|
|
}
|
|
|
|
print_to_ttys() {
|
|
who | while read -r _ TTY _; do
|
|
printf "Printing to %s\n" "$TTY"
|
|
printf "$@" > /dev/$TTY
|
|
done
|
|
}
|
|
|
|
print_to_ttys "\nRebooting in %d seconds, please save your work\n" "$1"
|
|
|
|
if [[ "$1" -gt 5 ]]; then
|
|
read -t "$(($1-5))" <><(:)||:
|
|
print_to_ttys "\nRebooting in %d seconds\n" 5
|
|
read -t 5 <><(:)||:
|
|
else
|
|
read -t $1 <><(:)||:
|
|
fi
|
|
|
|
systemctl reboot
|