Skip to content

Instantly share code, notes, and snippets.

@danmou
Last active June 10, 2024 08:47
Show Gist options
  • Save danmou/24523db341d0528f345deb25701a3cbd to your computer and use it in GitHub Desktop.
Save danmou/24523db341d0528f345deb25701a3cbd to your computer and use it in GitHub Desktop.
Replacement for the unix wall command, which also works with gnome-terminal
#!/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
@kjswanson
Copy link

kjswanson commented Jan 22, 2019

Hello Danmou,

I found this script from your SO post. I have a question I wonder you could help me with.

I am using this in conjunction with a python tool i created to manage aws ec2 instances from the command line.

I can successfully use your script in the command line with out needing higher level permission. However, when I use your script with in a python script... I am asked for permission before the script will finish. Once I give it the elevated permission it requests, the script will work fine untill the elevated permission times out.

I am using this on os x.

any thoughts?

Thanks for the script!
-KJS

Update:
So it seems that the original wall must have root privileges. Is this something that I can change in your script? Or is this a must based on permissions to be able to write to everyones terminal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment