-
-
Save Saya47/a9d2e918bd66139469b93fbe7897a1d7 to your computer and use it in GitHub Desktop.
Replacement for the unix wall command, which also works with gnome-terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage=" | |
Usage: | |
wall [options] [message] | |
Write a message to all users. | |
Options: | |
-n, --nobanner do not print banner | |
-h, --help display this help and exit | |
" | |
SHORT=nh | |
LONG=nobanner,help | |
PARSED=$(getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@") | |
if [[ $? -ne 0 ]]; then | |
echo "$usage" | |
exit 2 | |
fi | |
eval set -- "$PARSED" | |
while true; do | |
case "$1" in | |
-n|--nobanner) | |
n=y | |
shift | |
;; | |
-h|--help) | |
echo "$usage" | |
exit 0 | |
;; | |
--) | |
shift | |
break | |
;; | |
*) | |
exit 3 | |
;; | |
esac | |
done | |
ps -ef | grep " pts/" | awk '{print $6}' | sort -u > terminals_list.temp | |
ps -ef | grep " tty" | awk '{print $6}' | sort -u | grep -v "pts" >> terminals_list.temp | |
if [ "$n" ]; then | |
pre="" | |
post="" | |
else | |
pre="-e \nBroadcast message from $(whoami)@$(hostname) ($(ps ax | grep "^$$" | awk '{ print $2 }')) ($(date +"%a %b %d %H:%M:%S %Y")):\n\n" | |
post="\n" | |
fi | |
cat terminals_list.temp | while read TTY_TO; do echo $pre"$*"$post | sudo tee /dev/$TTY_TO 1>/dev/null; done | |
rm terminals_list.temp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment