-1

My /etc/rc.local is:

#!/bin/sh

touch /var/lock/subsys/local

/data/automatic/ntpdate.sh

My /data/automatic/ntpdate.sh is:

#!/bin/sh
echo "RWQERWER" >> /data/logs/1.log
ntpdate ntp.fudan.edu.cn >> /data/logs/1.log

The echo "RW...." is worked,ntp has installed. ntpdate.sh is 744 , but ntpdate ntp.fudan.edu.cn is run failed.

Outside at bash command line ,the /data/automatic/ntpdate.sh and ntpdate ntp.fudan.edu.cn >> /data/logs/1.log both run successfully .

What should I do ? Thanks first !

Sven
  • 98,649
  • 14
  • 180
  • 226
mike
  • 1
  • 1
  • 1
    What does "is run failed" means? Does `ntpdate` report an error into `/data/logs/1.log`? Maybe you get more info if you redirect STDERR as well: `ntpdate ntp.fudan.edu.cn >> /data/logs/1.log 2>&1` – Sven Jul 19 '13 at 07:17
  • 1
    I think the issue is that in bash script you must specify full path to the ntpdate. Try to replace ntpdate ntp.fudan.edu.cn on /usr/sbin/ntpdate ntp.fudan.edu.cn – ALex_hha Jul 19 '13 at 07:40
  • @ALex_hha: On my C6.4 the PATH that rc.local admits to is /sbin:/usr/sbin:/bin:/usr/bin - it's very strange. – user9517 Jul 19 '13 at 08:06
  • That 's the point ! bash and sh .... but even if I use the full path , it doesn't work anyway. – mike Jul 20 '13 at 04:30

2 Answers2

1

ntpdate is depreciated. You should install the NTP client and configure the ntpd daemon configuration file /etc/ntp.conf:

# cat /etc/ntp.conf | grep -v ^# | grep -v ^$
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
server europe.pool.ntp.org
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

And start the daemon

# service ntpd start
ALex_hha
  • 7,193
  • 1
  • 25
  • 40
  • no.I don't mean to use ntpd service ,just the ntpdate ,when ntpdate running,ntpd should closed. – mike Jul 19 '13 at 07:21
  • Could you clarify what do you want to get by running ntpdate once at system startup? – ALex_hha Jul 19 '13 at 07:27
  • 1
    @mike: Are you aware of the differences between `ntpdate` and `ntpd`? `ntpdate` will update the time once when you run it, whereas `ntpd` will continually update the time. – Sven Jul 19 '13 at 07:34
  • I just want to use ntpdate for once update time , not a ntpd service . – mike Jul 19 '13 at 09:19
  • 1
    @mike - Alex_hha has the right answer. [ntpdate](https://support.ntp.org/bin/view/Dev/DeprecatingNtpdate) has been deprecated. You should be running the NTP client service. –  Jul 21 '13 at 04:35
  • @kce The question is how to make ntpdate work. He's even explicitly stated that he does NOT want to use a service. So no, this neither a right or wrong answer... it's no answer at all. – dynamichael Jan 25 '19 at 08:56
1

I have no idea why you (and I get the same problem) can't capture the output of the command when run from rc.local.

If you want to capture it you can do something like

out=$(ntpdate ntp.fudan.edu.cn 2>&1)
echo $out >>/data/logs/1.log

which just worked on a system I have to hand.

user9517
  • 115,471
  • 20
  • 215
  • 297