make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / override / write
blob35deba77dd9c26cc30b04f02f26c896fa5ccd767
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 write - Wrapper for bsd-write, write(1), write to all terminals of the given user
10 =cut
12 EOF
15 declare -a opts=()
16 declare -a args=()
17 user=''
18 all_tty=''
20 while [ $# -gt 0 ]
22 case "$1" in
23 -h|--help)
24 echo "usage: write [--all-tty] [<user>]"
25 /usr/bin/write --help
26 exit
28 --all-tty)
29 all_tty=1
31 -*)
32 opts+=("$1")
35 args+=("$1")
37 if [ -z "$user" ]
38 then
39 user=$1
42 esac
43 shift
44 done
46 if [ "$all_tty" ]
47 then
48 message=`cat`
50 for tty in `utmp | awk -v user="$user" '$3 == user {print $2}'`
52 if [ -e "/dev/$tty" ]
53 then
54 echo "write: writing message on $tty" >&2
55 /usr/bin/write "${opts[@]}" "$user" "$tty" <<< "$message"
57 done
58 else
59 exec /usr/bin/write "${opts[@]}" "${args[@]}"