Problem mit Linux - Script-Dauerschleife beim Booten starten.

Legolasvegas

Lieutenant
Registriert
März 2010
Beiträge
520
So ich hab mir einen Linux Server auf Basis von Fedora und Amahi aufgebaut.

Funktionen hatte ich gerade alle soweit, dass alles wunderbar Funktioniert
(Filserver,Backup, WakeonLan und Mediastreaming)

Jedoch sind auch die STromkosten ein wichtiger Faktor, weshalb ich eine automatisches Abschalten haben will.
Darauf habe ich ein gutes Script gefunden
#!/bin/bash
# Filename : autoshutdown.sh


class=192.168.0 # Set the IP base class.
flag=0 # Initialise the counter.
flag1=3 # Set the number of total failure before shutdown.
SLEEP=60 # Numbers of seconds between each check/loop.
iSTART=200 # Start IP address
iEND=100 # End IP address
iSHUTDOWN=1 # Are we allowed to shutdown?

_ping_range()
{
cnt=0
i=${iSTART}

while (( i>=iEND && cnt==0 )); do
# Ping each IP address in turn. counting downwards because we know that DHCP on
# the the network starts at 200 and assigns downwards to 100 so we're more
# likely to find a live one in the high numbers, if we find one ie cnt != 0 we'll
# stop as there's really no point continuing to looking for more.
/sbin/ping -c 1 -s 8 -t 1 ${class}.${i}

if [ $? -eq 0 ]; then
# Found one!!
let cnt++;
iSHUTDOWN=0;
fi

let i--;
done

if [ $iSHUTDOWN -eq 1 ]; then
# If iSHUTDOWN is still 1 at this point then we've not found an active IP address
# since the script started running, so we'll just pretend we have so the system stays up.
cnt=1;
fi

return ${cnt};
}

_shutdown()
{
if [ $flag -eq $flag1 ];then
# Goodbye and thanks for all the fish!!
# We've had no responses for the required number of consecutive scans
# defined in flag1 shutdown & power off.
/sbin/shutdown -p now
exit 0;
fi
}

while : ; do
# Main loop, just keep pinging and checking
_ping_range

if [ $? -eq 0 ];then
# Nothing found so add one to the count and check if we can shutdown yet.
let flag++;
_shutdown;
else
# Live IP found so reset count
flag=0;
fi

# Wait for the required time before checking again.
/bin/sleep $SLEEP;
done
Quelle : Klickmich

Ja das Script ist eine Dauerschleife. Das bedeutet, es wird immer über Ping ein bestimmter Bereich abgefragt. Wenn keine Antwort kommt läuft das Script noch 3 mal alle 60s durch. Erst wenn dann immer noch keine Antwort kommt, kommt der Shutdown Befehl.

Das Script läuft einwand frei jedoch, will ich es natürlich auch bei Systemstart einfügen. Ohne drüber nach zudenken hab ich es in die /etc/rc.d/rc.local gepackt und rebootet. Wie mir nen paar Sekunden später (zu Spät) eingefallen ist, ist eine Dauerschleife im Boot-Vorgang ne Dumme Idee udn genauso war s auch System-Startet nciht mehr bzw. hängt sich auf.

Jetzt zu meiner Frage: Wie bekomm ich das Script zum System start hin aktiviert ohne in die Schleife zu geraten?
Idee, welche ich hatte war einfach ein Script, welche das Script startet also

#!/bin/bash
/etc(...) Filename.sh

Würde das gehen . Möchte es nicht nochmal versuchen weil das neu aufsetzten des Systems doch recht lange dauert.

Und Muss noch ein bestimmter Befehl rein oder reicht das so?

gruß
Legolasvegas
 
das was IceMatrix geschrieben hat stimmt auf jeden fall, neu aufsetzen müsstest du aber sowieso nicht, einfach mit livecd booten, das filesystem mounten und rc.local anpassen.
 
also als script
#!bin/bash
/etc(...)Filename.sh&

das wars? okay danke
Ja ist schon neu aufgesetzt, wiel ich das mit ner live cdn icht hinbekommen hab
Ergänzung ()

Okay das geht so auch nicht... irgendwie will das alles nicht so wie ich will. Dem dem Script ,welches das Script startet geht auch nicht. Versuch das grad über auto login usw. falls wer noch ne gute idee hat wäre ich um hilfe echt dankbar
 
Zurück
Oben