ShutdownScript

Aus Foxwiki

Ziel

Geräte im Netzwerk finden und Shutdown auslösen

#!/bin/bash
activeips=$(nmap -v -sn -n -T4 10.10.0.2-254 | grep -v down | grep [0-9]$ | cut -d " " -f 5 | sed '1d')
for IP in $activeips;
do
#echo "$activeips"
ssh -o "StrictHostKeyChecking no" root@$IP 'shutdown -h now';
done

Authorization Key erzeugen

#!/bin/bash
for X in $(cut -f6 -d ':' /etc/passwd |sort |uniq); do
 for suffix in "" "2"; do
   if [ -s "${X}/.ssh/authorized_keys$suffix" ]; then
     echo "### ${X}: "
     cat "${X}/.ssh/authorized_keys$suffix"
     echo ""
    fi;
  done;
done

Public Keys auf alle Geräte kopieren

#!/bin/bash
nmap -v -sn -n -T4 10.10.0.0/24 | grep -v down | grep [0-9]$ | cut -d " " -f 5 | sed '1d' | sed '$d' > pubids.txt
while read pubids
do
 echo "$pubids"
 sshpass -p "123456" ssh-copy-id -f -i ~/.ssh/id_rsa.pub root@$pubids
done