Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[OT] wie lenke ich die ausgabe von ntpdate in variable um?
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
schrippe
Guru
Guru


Joined: 03 Mar 2004
Posts: 556
Location: Mülheim

PostPosted: Fri Aug 06, 2004 7:56 am    Post subject: [OT] wie lenke ich die ausgabe von ntpdate in variable um? Reply with quote

ich möchte das ein ntpdate auf einem rechner stündlich abläuft und will mir ins syslog die zeitdifferenz eintragen lassen, bis jetzt bin ich soweit:

data2:~ # cat /etc/cron.hourly/ntpdate
#!/bin/sh
CLOCK=(`ntpdate 192.168.121.1`)
logger "ntpdate fertig!"
logger `echo $CLOCK`
hwclock --systohc

jetzt ist es so, das er nur das erste zeichen der ausgabe von ntpdate in CLOCK schreibt. in diesem fall 6 von 6. august

müsste doch auch gehen, das er ganze strings in der varibale ablegt, oder?

danke

mod edit: +[OT]
amne
Back to top
View user's profile Send private message
schmutzfinger
Veteran
Veteran


Joined: 26 Oct 2003
Posts: 1287
Location: Dresden/Germany

PostPosted: Fri Aug 06, 2004 8:23 am    Post subject: Reply with quote

vielleicht weil da ein ` am ende fehlt?
Back to top
View user's profile Send private message
schrippe
Guru
Guru


Joined: 03 Mar 2004
Posts: 556
Location: Mülheim

PostPosted: Fri Aug 06, 2004 8:30 am    Post subject: Reply with quote

ne das ` ist da, wird nur von der klammer hier im text verschluckt.
Back to top
View user's profile Send private message
Rafje
Tux's lil' helper
Tux's lil' helper


Joined: 19 May 2004
Posts: 109
Location: .be

PostPosted: Fri Aug 06, 2004 8:31 am    Post subject: Reply with quote

Excuse me for my English, aber ich kein Deutsch sprechen.

What if you try this instead:
Code:
[...]
CLOCK=`ntpdate 192.168.121.1` #I don't understand why you'd put parenthesis here...
[...]
logger "$CLOCK"
[...]

Cheers
Back to top
View user's profile Send private message
rojaro
l33t
l33t


Joined: 06 May 2002
Posts: 732

PostPosted: Fri Aug 06, 2004 8:31 am    Post subject: Reply with quote

Probier das ma :)
Code:
#!/bin/sh
CLOCK=$(ntpdate 192.168.121.1 2>&1)
logger "ntpdate fertig!"
logger $CLOCK
hwclock --systohc

_________________
A mathematician is a machine for turning coffee into theorems. ~ Alfred Renyi (*1921 - †1970)
Back to top
View user's profile Send private message
rojaro
l33t
l33t


Joined: 06 May 2002
Posts: 732

PostPosted: Fri Aug 06, 2004 8:36 am    Post subject: Reply with quote

Rafje,
Rafje wrote:
CLOCK=`ntpdate 192.168.121.1` #I don't understand why you'd put parenthesis here...

The backticks basically mean return the output of the command between them backticks to the variable. Altough the backticks work, they're deprecated and should be replaced by $( and ) as it also makes nesting possible. e.g.
Code:
RESULT=$(command1 $(command2))

the output of command2 will be used as parameter for command1 and the output of command1 will be stored in the RESULT variable.
_________________
A mathematician is a machine for turning coffee into theorems. ~ Alfred Renyi (*1921 - †1970)
Back to top
View user's profile Send private message
Rafje
Tux's lil' helper
Tux's lil' helper


Joined: 19 May 2004
Posts: 109
Location: .be

PostPosted: Fri Aug 06, 2004 8:47 am    Post subject: Reply with quote

Thank you for your explanation, rojaro, but I already knew about the $() :)
I was just wondering why in the initial script, schrippe uses backtics AND parenthesis
Code:
X=(`cmd`)
as if he wanted to execute it in a separate shell...

Thanks anyway
Tschuss
Back to top
View user's profile Send private message
schrippe
Guru
Guru


Joined: 03 Mar 2004
Posts: 556
Location: Mülheim

PostPosted: Fri Aug 06, 2004 9:51 am    Post subject: Reply with quote

i am not very good in bash scripting.
i have forgotten the meaning of (). it wasn't my intention to use a separate shell.
but now, the problem is solved.

thanks
Back to top
View user's profile Send private message
toskala
Advocate
Advocate


Joined: 14 Dec 2002
Posts: 2080
Location: hamburg, germany

PostPosted: Fri Aug 06, 2004 12:47 pm    Post subject: Reply with quote

maybe you want to read

http://www.tldp.org/LDP/abs/html/
_________________
adopt an unanswered post
erst denken, dann posten
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3922
Location: Hamburg

PostPosted: Fri Aug 06, 2004 7:34 pm    Post subject: Reply with quote

Code:

tfoerste@nhh221 ~ $ C="$(ntpdate -q 2>&1)"
tfoerste@nhh221 ~ $ echo $C
6 Aug 21:33:36 ntpdate[8150]: no servers can be used, exiting
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum