Zum Inhalt springen

ShutdownScript: Unterschied zwischen den Versionen

Aus Foxwiki
Keine Bearbeitungszusammenfassung
K Textersetzung - „ “ durch „ “
 
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 12: Zeile 12:
  #!/bin/bash
  #!/bin/bash
  for X in $(cut -f6 -d ':' /etc/passwd |sort |uniq); do
  for X in $(cut -f6 -d ':' /etc/passwd |sort |uniq); do
  for suffix in "" "2"; do
for suffix in "" "2"; do
    if [ -s "${X}/.ssh/authorized_keys$suffix" ]; then
  if [ -s "${X}/.ssh/authorized_keys$suffix" ]; then
      echo "### ${X}: "
  echo "### ${X}: "
      cat "${X}/.ssh/authorized_keys$suffix"
  cat "${X}/.ssh/authorized_keys$suffix"
      echo ""
  echo ""
    fi;
  fi;
  done;
  done;
  done
  done


Zeile 26: Zeile 26:
  while read pubids
  while read pubids
  do
  do
  echo "$pubids"
echo "$pubids"
  sshpass -p "123456" ssh-copy-id -f -i ~/.ssh/id_rsa.pub root@$pubids
sshpass -p "123456" ssh-copy-id -f -i ~/.ssh/id_rsa.pub root@$pubids
  done
  done


[[Category:Projekte]]
[[Kategorie:Ausbildung]]

Aktuelle Version vom 14. Juni 2026, 00:49 Uhr

Ziele

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