View previous topic :: View next topic |
Author |
Message |
schrippe Guru
Joined: 03 Mar 2004 Posts: 556 Location: Mülheim
|
Posted: Fri Aug 06, 2004 7:56 am Post subject: [OT] wie lenke ich die ausgabe von ntpdate in variable um? |
|
|
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 |
|
|
schmutzfinger Veteran
Joined: 26 Oct 2003 Posts: 1287 Location: Dresden/Germany
|
Posted: Fri Aug 06, 2004 8:23 am Post subject: |
|
|
vielleicht weil da ein ` am ende fehlt? |
|
Back to top |
|
|
schrippe Guru
Joined: 03 Mar 2004 Posts: 556 Location: Mülheim
|
Posted: Fri Aug 06, 2004 8:30 am Post subject: |
|
|
ne das ` ist da, wird nur von der klammer hier im text verschluckt. |
|
Back to top |
|
|
Rafje Tux's lil' helper
Joined: 19 May 2004 Posts: 109 Location: .be
|
Posted: Fri Aug 06, 2004 8:31 am Post subject: |
|
|
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 |
|
|
rojaro l33t
Joined: 06 May 2002 Posts: 732
|
Posted: Fri Aug 06, 2004 8:31 am Post subject: |
|
|
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 |
|
|
rojaro l33t
Joined: 06 May 2002 Posts: 732
|
Posted: Fri Aug 06, 2004 8:36 am Post subject: |
|
|
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 |
|
|
Rafje Tux's lil' helper
Joined: 19 May 2004 Posts: 109 Location: .be
|
Posted: Fri Aug 06, 2004 8:47 am Post subject: |
|
|
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 as if he wanted to execute it in a separate shell...
Thanks anyway
Tschuss |
|
Back to top |
|
|
schrippe Guru
Joined: 03 Mar 2004 Posts: 556 Location: Mülheim
|
Posted: Fri Aug 06, 2004 9:51 am Post subject: |
|
|
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 |
|
|
toskala Advocate
Joined: 14 Dec 2002 Posts: 2080 Location: hamburg, germany
|
|
Back to top |
|
|
toralf Developer
Joined: 01 Feb 2004 Posts: 3922 Location: Hamburg
|
Posted: Fri Aug 06, 2004 7:34 pm Post subject: |
|
|
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 |
|
|
|