Renaud OLGIATI [2016-01-30 16:33:31-03] wrote: > Is there a way for a system admin to post a message on the desktops of > all the machines on a LAN ?
I'm doing the same thing in a network where every machine gets their IP through DHCP. The network is scanned with nmap for open ssh servers. Luckily on every machine there is always the same Linux user. Every machine has ssh server, admin's ssh public key in .authorized_keys file and gxmessage package. My script that can do different maintenance tasks but here's a stripped version that has only the message part. --8<---------------cut here---------------start------------->8--- #!/bin/bash network=192.168.0.0/24 gpgkey=08:6d:f8:f4:aa:73:5c:d9:4c:f8:02:a1:f6:12:e3:1d gpgkeyfile=$HOME/.ssh/admin_key_rsa userhome=/home/user message=$(printf '%q' "$*") timestamp=$(date '+%Y-%m-%d %H:%M') set -- XAUTHORITY=$userhome/.Xauthority \ gxmessage -display :0 -fn "'Sans 20'" -wrap \ -geometry 800x500 -center -title "'Message $timestamp'" \ "$message" ssh-add -l | grep -F -q -e "$gpgkey" || ssh-add "$gpgkeyfile" || exit 1 unset NFS echo "Looking for open ssh servers in network $network..." ips=( $(nmap -T4 -PE -sS -n -p 22 "$network" | \ awk '/report for/ {ip=$5} /open *ssh/ {print ip}') ) total=${#ips[@]} if [ "$total" -eq 0 ]; then echo "Didn't find any machines." exit 1 fi i=1 for ip in "${ips[@]}"; do echo "$i/$total $ip: Connecting to machine..." ssh -qf -o StrictHostKeyChecking=no -o BatchMode=yes root@"$ip" "$@" let i++ done --8<---------------cut here---------------end--------------->8--- -- /// Teemu Likonen - .-.. <https://github.com/tlikonen> // // PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///
signature.asc
Description: PGP signature