Moxa TC-6110-T-LX [13/117] Setting a time manually

Moxa TC-6110-T-LX [13/117] Setting a time manually
TC-6110 Linux User's Manual Basic Platform Configuration
2-6
Sample shell script for scheduled clock synchronizations
You may save this shell script using any file name, but it should be saved in the /etc/init.d directory. For
example,
/etc/init.d/fixtime.sh.
#!/bin/sh
ntpdate time.stdtime.gov.tw
# You can use the time server’s ip address or domain
# name directly. If you use domain name, you must
# enable the domain client on the system by updating
# /etc/resolv.conf file.
hwclock –w
sleep 100
# Updates every 100 seconds. The min. time is 100 seconds.
# Change 100 to a larger number to update the RTC less often.
How to run a shell script automatically across re-boots
Copy the example above shell script fixtime.sh to the directory /etc/init.d, and then set its access
permissions to 755.
moxa@MOXA:~# chmod 755 fixtime.sh
Next, use open the initialization table (inittab) for editing in your preferred editor (we use VI as an example):
moxa@MOXA:~# vi /etc/inittab
Add the following line to the bottom of the file:
ntp : 2345 : respawn : /etc/init.d/fixtime.sh
Use the command #init q to re-initialize the kernel.
moxa@MOXA:~# init q
NOTE
In *nix environments, when inserting a single line at the end of a configuration file it is possible to use a single
line command. This allows administrators to save time without opening the config file in an edtor. To insert a
single ine to the end of a file, use the
echo command with input redirects:
moxa@MOXA:~# echo “ntp : 2345 : respawn : /etc/init.d/fixtime
>> /etc/inittab
Keep in mind, howev
er, that care must be taken to use a double caret (>>)
. Use of a single caret (>) indicates
overwriting the entire file with the single line, and will erase the current configuration.
Setting a Time Manually
System Time
When called with unquoted arguments, the date command will reset the system clock. The time and date must
be entered in the format of Month-Date-Hour-Minute-Year.
moxa@MOXA:~# date [MMDDhhmmYYYY]
Month, date, hour, and minute are all entered in a two digit code, with the year entered using the full four digits,
as shown below:
MM: Month
DD: Date
hhmm: Hour and Minute
YYYY: Year
moxa@MOXA:~# date
Tue Aug 20 11:28:05 CST 2013
moxa@MOXA:~# sudo hwclock
[sudo] password for moxa:
Tue 20 Aug 2013 11:28:47 AM CST -0.422555 seconds
moxa@MOXA:~# date 121616352009
Wed Dec 16 16:35:00 CST 2009

Содержание

Похожие устройства

Скачать