Long_press/long_press.sh
Michael Haider 2d5f72ad40 Fix check_autoboot_status to correctly identify and terminate autoboot_win.sh without including current SSH session process.
Adjusted the check_autoboot_status function in long_press.sh to use pgrep with -af and grep -v 8424 to exclude the current process, ensuring accurate detection and termination of autoboot_win.sh on the remote device.

Added output for terminated_successfully status to indicate script completion and readiness for subsequent actions.

Fixes: #123
2024-06-19 17:36:04 +02:00

80 lines
2.4 KiB
Bash

#!/bin/bash
# Aktiviert das Debugging
set -x
# Pfadvariable setzen
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# # Reboot to Linux
# if ping -c 3 192.168.178.80 > /dev/null; then
# /usr/bin/ssh -i /root/.ssh/windows -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null Ratatoskr@192.168.178.80 "shutdown /r /t 0"
# fi
# Boot Linux
etherwake 70:85:c2:d1:40:ef
# Wartezeit nach dem Wake-on-LAN (z.B. 10 Sekunden)
echo "Warte 10 Sekunden, damit das System vollständig hochfährt..."
sleep 10
# Startzeit der Schleife speichern
start_time=$(date +%s)
# Zeitdauer in Sekunden, für die die Schleife laufen soll (2 Minuten)
duration=120
# Funktion, um Prozess auf dem Remote-Gerät zu überprüfen
check_autoboot_status() {
/usr/bin/ssh -i /root/.ssh/id_rsa root@192.168.178.80 '
if /usr/bin/pgrep -af "autoboot_win.sh" | grep -v $$; then
echo "running"
/usr/bin/pkill -f "autoboot_win.sh"
else
echo "not_running"
fi
'
}
# Variable, um den Status des Beendens zu speichern
terminated_successfully=false
while true; do
# Prozessstatus auf dem Remote-Gerät überprüfen
status=$(check_autoboot_status)
if [ "$status" = "not_running" ]; then
echo "autoboot_win.sh ist nicht mehr aktiv."
terminated_successfully=true
break
else
echo "autoboot_win.sh läuft noch."
fi
# Aktuelle Zeit in Sekunden seit dem Epoch berechnen
current_time=$(date +%s)
# Überprüfen, ob die Zeitdauer überschritten wurde
if (( current_time - start_time >= duration )); then
echo "Zeitlimit von 2 Minuten erreicht. Beende die Schleife."
break
fi
echo "Warte 5 Sekunden..."
sleep 5
done
# Status von "terminated_successfully" ausgeben
echo "### Variable 'terminated_successfully' ist $terminated_successfully ###"
# Wenn das Skript erfolgreich beendet wurde, Handshakes übertragen und cracking-Skript starten
if [ "$terminated_successfully" = true ]; then
echo "Übertrage Handshakes und starte crack_handshakes.sh"
scp -i /root/.ssh/id_rsa /root/handshakes/*.22000 root@192.168.178.80:/root/handshakes/
# Starte crack_handshakes.sh in einer tmux-Sitzung
/usr/bin/ssh -i /root/.ssh/id_rsa root@192.168.178.80 "tmux new-session -d -s crack_handshakes '/root/crack_handshakes.sh'"
else
echo "autoboot_win.sh konnte nicht beendet werden. Übertragung der Handshakes und Starten des cracking-Skripts wird übersprungen."
fi