Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 !

share|improve this question

closed as unclear what you're asking by Lucas Kauffman, Wesley, Scott Pack, Falcon Momot, Ward Jul 21 '13 at 5:10

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

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 –  SvW Jul 19 '13 at 7: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 7: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. –  Iain Jul 19 '13 at 8: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 4:30

2 Answers 2

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
share|improve this answer
    
no.I don't mean to use ntpd service ,just the ntpdate ,when ntpdate running,ntpd should closed. –  mike Jul 19 '13 at 7:21
    
Could you clarify what do you want to get by running ntpdate once at system startup? –  ALex_hha Jul 19 '13 at 7: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. –  SvW Jul 19 '13 at 7:34
    
I just want to use ntpdate for once update time , not a ntpd service . –  mike Jul 19 '13 at 9:19
1  
@mike - Alex_hha has the right answer. ntpdate has been deprecated. You should be running the NTP client service. –  kce Jul 21 '13 at 4:35

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.

share|improve this answer
    
Actually , it's a very simple question ,you just use my code like my way ,and you will figure out . –  mike Jul 19 '13 at 9:22
    
@mike: I'm sorry I don't understand your comment. –  Iain Jul 19 '13 at 10:29
    
I'm so sorry, I try my best to let you understand ,but I am an Aisan , english is so difficult to me . aplogizes! –  mike Jul 20 '13 at 4:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.