Author |
Message |
A374
Joined: 19 Jan 2009 Posts: 12
|
Posted: Sun 25 Nov 2012, 02:18 Post subject:
Wer kennt sich mit Script-Programmierung aus und kann helfen |
|
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
Quote: | 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
Quote: | 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
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 3431 Location: www.eussenheim.de/
|
Posted: Sun 25 Nov 2012, 07:10 Post subject:
Re: Wer kennt sich mit Script-Programmierung aus und kann helfen |
|
[quote="A374" Datum + Uhrzeit aus /tmp/date[/quote]
Code: | x="`grep '^<current_time>' /tmp/date`" |
<current_time>Sun Nov 25 05:14:54 2012
Sun Nov 25 05:14:54 2012
Code: | x="`grep '^<current_time>' /tmp/date`"
x=${x##*>}
echo
'rm /etc/adjtime
hwclock --set --date="'$x'" --localtime
hwclock --hctosys' > hwclock_eintrag |
Hoofe das hilft.
|
Back to top
|
|
 |
A374
Joined: 19 Jan 2009 Posts: 12
|
Posted: Sun 25 Nov 2012, 16:03 Post subject:
|
|
Hallo.
Vielen Dank für Deine Hilfe.
Leider funktioniert Dein Script nicht.
Datei /tmp/date existiert
Code: | ?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: | # x="`grep '^<current_time>' /tmp/date`"
# x=${x##*>}
# echo $x
# |
dann wird nichts angezeigt.
Wenn ich jetzt folgendes Script ausführe:
Code: | #!/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: | # ./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
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 3431 Location: www.eussenheim.de/
|
Posted: Sun 25 Nov 2012, 16:18 Post subject:
|
|
A374 wrote: |
Datei /tmp/date existiert
Code: | ?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: | # x="`grep '^<current_time>' /tmp/date`"
# x=${x##*>}
# echo $x
# |
dann wird nichts angezeigt. |
Ja, dann halt ohne das "Dächlein" ^
Code: | x="`grep '<current_time>' /tmp/date`" |
|
Back to top
|
|
 |
A374
Joined: 19 Jan 2009 Posts: 12
|
Posted: Sun 25 Nov 2012, 17:07 Post subject:
|
|
Quote: |
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: | # ./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: | hwclock --set date="[monat]/[tag]/[jahr] [stunde]:[min]:[sek]" --localtime |
|
Back to top
|
|
 |
A374
Joined: 19 Jan 2009 Posts: 12
|
Posted: Sun 25 Nov 2012, 22:15 Post subject:
|
|
Hallo,
hat sich erledigt. Ich hab es jetzt folgendermassen lösen können:
Code: | #!/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
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 3431 Location: www.eussenheim.de/
|
Posted: Mon 26 Nov 2012, 04:32 Post subject:
|
|
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"
|
Back to top
|
|
 |
A374
Joined: 19 Jan 2009 Posts: 12
|
Posted: Mon 26 Nov 2012, 23:17 Post subject:
|
|
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: |
#!/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: |
#!/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
|
Back to top
|
|
 |
|