Page 1 of 1
Wer kennt sich mit Script-Programmierung aus und kann helfen
Posted: Sun 25 Nov 2012, 06:18
by A374
Hallo,
ich möchte von einem Linux Satelliten Receiver das Datum + Uhrzeit auslesen und anschliessend die Uhr von Puppy Linux danach stellen.
Das auslesen des Satelliten Receivers bringt folgendes Ergebnis
wget -q
http://192.168.10.112/xml/boxstatus --user=root --password= -O /tmp/date
<?xml version="1.0" encoding="UTF-8"?>
<boxstatus>
<current_time>Sun Nov 25 05:14:54 2012
</current_time>
<standby>1</standby>
<recording>0</recording>
<mode>0</mode>
<ip>192.168.10.112</ip>
</boxstatus>
Was mir jetzt fehlt ist ein Script, dass das Datum + Uhrzeit aus /tmp/date liest und es an folgendes script übergibt
rm /etc/adjtime
hwclock --set --date="9/22/96 16:45:05" --localtime
hwclock --hctosys
Ich kann also das Datum + Uhrzeit auslesen und in eine Datei schreiben lassen. Des weiteren weiss ich auch, wie ich das Datum einstellen kann. Es fehlt mir nur ein Script, dass das Datum + Uhrzeit aus /tmp/date in meinen hwclock-eintrag einfügt.
Hoffentlich kann mir jemand helfen.
Gruss
Re: Wer kennt sich mit Script-Programmierung aus und kann helfen
Posted: Sun 25 Nov 2012, 11:10
by L18L
[quote="A374" Datum + Uhrzeit aus /tmp/date[/quote]
Code: Select all
x="`grep '^<current_time>' /tmp/date`"
<current_time>Sun Nov 25 05:14:54 2012
Sun Nov 25 05:14:54 2012
Code: Select all
x="`grep '^<current_time>' /tmp/date`"
x=${x##*>}
echo
'rm /etc/adjtime
hwclock --set --date="'$x'" --localtime
hwclock --hctosys' > hwclock_eintrag
Hoofe das hilft.
Posted: Sun 25 Nov 2012, 20:03
by A374
Hallo.
Vielen Dank für Deine Hilfe.
Leider funktioniert Dein Script nicht.
Datei /tmp/date existiert
Code: Select all
?xml version="1.0" encoding="UTF-8"?>
<boxstatus>
<current_time>Sun Nov 25 20:52:22 2012
</current_time>
<standby>1</standby>
<recording>0</recording>
<mode>0</mode>
<ip>192.168.10.112</ip>
</boxstatus>
Wenn ich nacheinander folgendes eingebe:
Code: Select all
# x="`grep '^<current_time>' /tmp/date`"
# x=${x##*>}
# echo $x
#
dann wird nichts angezeigt.
Wenn ich jetzt folgendes Script ausführe:
Code: Select all
#!/bin/sh
wget -q http://192.168.10.112/xml/boxstatus --user=root --password= -O /tmp/date
x="`grep '^<current_time>' /tmp/date`"
x=${x##*>}
echo $x
rm /etc/adjtime
hwclock --set --date="'$x'" --localtime
hwclock --hctosys
kommt folgende Meldung:
Code: Select all
# ./uhr
rm: cannot remove `/etc/adjtime': No such file or directory
date: invalid date `\'\''
The date command issued by hwclock returned unexpected results.
The command was:
date --date="''" +seconds-into-epoch=%s
The response was:
No usable set-to time. Cannot set clock.
Vielleicht hast Du ja noch ne Idee?
Gruss
Posted: Sun 25 Nov 2012, 20:18
by L18L
A374 wrote:
Datei /tmp/date existiert
Code: Select all
?xml version="1.0" encoding="UTF-8"?>
<boxstatus>
<current_time>Sun Nov 25 20:52:22 2012
</current_time>
<standby>1</standby>
<recording>0</recording>
<mode>0</mode>
<ip>192.168.10.112</ip>
</boxstatus>
Wenn ich nacheinander folgendes eingebe:
Code: Select all
# x="`grep '^<current_time>' /tmp/date`"
# x=${x##*>}
# echo $x
#
dann wird nichts angezeigt.
Ja, dann halt ohne das "Dächlein"
^
Code: Select all
x="`grep '<current_time>' /tmp/date`"
Posted: Sun 25 Nov 2012, 21:07
by A374
Ja, dann halt ohne das "Dächlein" ^
Danke. Jetzt wird das Datum angezeigt.
Ich will ja wirklich nicht nerven, aber ich hab jetzt noch das Problem, dass das Datum im falschen Format vorliegt und deshalb nicht mit hwclock gesetzt werden kann. Kann man das Datum irgendwie umbiegen?
Code: Select all
# ./uhr
Sun Nov 25 21:58:58 2012
date: invalid date `\'Sun Nov 25 21:58:58 2012\''
The date command issued by hwclock returned unexpected results.
The command was:
date --date="'Sun Nov 25 21:58:58 2012'" +seconds-into-epoch=%s
The response was:
No usable set-to time. Cannot set clock.
#
Das Format müsste für hwclock folgendermassen sein:
Code: Select all
hwclock --set date="[monat]/[tag]/[jahr] [stunde]:[min]:[sek]" --localtime
Posted: Mon 26 Nov 2012, 02:15
by A374
Hallo,
hat sich erledigt. Ich hab es jetzt folgendermassen lösen können:
Code: Select all
#!/bin/sh
wget -q http://192.168.10.112/xml/boxstatus --user=root --password= -O /tmp/date
if [ ! -s /tmp/date ];
then
echo Datei ist leer;
rm /tmp/date
else
x="`grep '<current_time>' /tmp/date`"
x=${x##*>}
echo $x
rm /etc/adjtime
date -s "$x"
hwclock --systohc
rm /tmp/date
fi
Vielen Dank für Deine Hilfe und die Mühe die Du dir gemacht hast.
Gruss
Posted: Mon 26 Nov 2012, 08:32
by L18L
A374 wrote:...Ich hab es jetzt folgendermassen lösen können...
Wirklich?
Falls /tmp/date leer ist, wird sie gelöscht.
Sonst nichts!
Kein "Wiederhole bis erfolgreich"
Posted: Tue 27 Nov 2012, 03:17
by A374
Ja, ist schon richtig so. "Wiederhole bis erfolgreich" würde nichts bringen. Wenn nämlich der Satelliten Receiver z.B. ausgeschaltet ist, dann besteht auch keine Netzwerkverbindung zu ihm. Dann könnte Das Script so oft wiederholen wie es wollte, aber erfolglos. Wenn ich mit wget die Infos von dem Receiver abfrage und keine Netzwerkverbindung besteht, dann legt wget eine leere /tmp/date an. Wenn ich diese leere /tmp/date verwende um das Datum daraus zu erstellen, dann wird das Datum nicht verändert, aber die Uhrzeit wird dann auf 00:00 Uhr gesetzt. Dann sage ich lieber: keine Uhrzeit setzen und /tmp/date löschen, als die Uhrzeit auf 00:00 Uhr zu setzen.
Meine Endversion des Scriptes sieht jetzt folgendermassen aus
Code: Select all
#!/bin/sh
wget -q http://192.168.10.112/xml/boxstatus --user=root --password= -O /tmp/date
if [ ! -s /tmp/date ]; then
echo Datei ist leer;
rm /tmp/date
else
x="`grep '<current_time>' /tmp/date`"
x=${x##*>}
echo $x
rm /etc/adjtime
date -s "$x"
hwclock --systohc
rm /tmp/date
touch /tmp/datum
fi
if [ -e /tmp/datum ]; then
echo Datum ist bereits aktualisiert;
else
wget -q http://192.168.10.117/xml/boxstatus --user=root --password= -O /tmp/date
if [ ! -s /tmp/date ]; then
echo Datei ist leer;
rm /tmp/date
else
x="`grep '<current_time>' /tmp/date`"
x=${x##*>}
echo $x
rm /etc/adjtime
date -s "$x"
hwclock --systohc
rm /tmp/date
touch /tmp/datum
fi
fi
if [ -e /tmp/datum ]; then
echo Datum ist bereits aktualisiert;
else
wget -q http://192.168.10.115/xml/boxstatus --user=root --password= -O /tmp/date
if [ ! -s /tmp/date ]; then
echo Datei ist leer;
rm /tmp/date
else
x="`grep '<current_time>' /tmp/date`"
x=${x##*>}
echo $x
rm /etc/adjtime
date -s "$x"
hwclock --systohc
rm /tmp/date
touch /tmp/datum
fi
fi
if [ -e /tmp/datum ]; then
echo Datum ist bereits aktualisiert;
else
wget -q http://192.168.10.114/xml/boxstatus --user=root --password= -O /tmp/date
if [ ! -s /tmp/date ]; then
echo Datei ist leer;
rm /tmp/date
else
x="`grep '<current_time>' /tmp/date`"
x=${x##*>}
echo $x
rm /etc/adjtime
date -s "$x"
hwclock --systohc
rm /tmp/date
touch /tmp/datum
fi
fi
if [ -e /tmp/datum ]; then
echo Datum ist bereits aktualisiert;
else
wget -q http://192.168.10.116/xml/boxstatus --user=root --password= -O /tmp/date
if [ ! -s /tmp/date ]; then
echo Datei ist leer;
rm /tmp/date
else
x="`grep '<current_time>' /tmp/date`"
x=${x##*>}
echo $x
rm /etc/adjtime
date -s "$x"
hwclock --systohc
rm /tmp/date
touch /tmp/datum
fi
fi
if [ -e /tmp/datum ]; then
echo Datum ist bereits aktualisiert;
else
wget -q http://192.168.10.113/control/gettime --user=root --password=root -O /tmp/date
if [ ! -s /tmp/date ]; then
echo Datei ist leer;
rm /tmp/date
else
x="`grep '' /tmp/date`"
x=${x##*>}
echo $x
rm /etc/adjtime
date -s "$x"
hwclock --systohc
rm /tmp/date
touch /tmp/datum
fi
fi
if [ -e /tmp/datum ]; then
echo Datum ist bereits aktualisiert;
else
./date_ufs910_expect
sleep 2
rm /tmp/date
wget -q ftp://192.168.10.135/tmp/date --user=root --directory-prefix=/tmp
if [ ! -s /tmp/date ]; then
echo Datei ist leer;
rm /tmp/date
else
x="`grep '' /tmp/date`"
x=${x##*>}
echo $x
rm /etc/adjtime
date -s "$x"
hwclock --systohc
rm /tmp/date
touch /tmp/datum
fi
fi
if [ -e /tmp/datum ]; then
echo Datum ist bereits aktualisiert;
rm /tmp/datum
else
[ ! "`grep 'ntp 123/tcp' /etc/services`" ] && echo -e "ntp 123/tcp\nntp 123/udp" >> /etc/services
rm /etc/adjtime
sleep 1
ntpdate -t 2 192.168.10.135 192.168.10.112 192.168.10.113 192.168.10.114 192.168.10.115 192.168.10.116 192.168.10.117; hwclock -u --systohc &
rm /tmp/datum
fi
Und hier noch die passende date_ufs910_expect
Code: Select all
#!/usr/bin/expect -f
set benutzername root
spawn telnet "192.168.10.135"
expect "Username:"
send "$benutzername\r"
sleep 2
send "rm /tmp/date\r"
send "date +%c > tmp/date\r"
sleep 1
send "exit\r"
expect "Connection closed by foreign host."
Wie Du siehst verhält es sich so, dass wenn ein Receiver keine Lan-Verbindung hat weil z.B. ausgeschaltet, dann wird einfach der nächste abgefragt. Irgend einer antwortet bestimmt
Wie im vorherigen Post bereits erwähnt, nochmals vielen Dank für Deine Hilfe. Denn sonst hätte ich es vermutlich nicht hinbekommen.
Gruss