为什么在crontab中使用ntpdate同步时间无效?

在一台 VirtualBox 上安装的 CentOS 5.8 系统上,时间不准确,一天能差上好几个小时,每次测试与时间相关的程序时,总得先去调整时间。于是在crontab中设置了一个定时任务:(crontab -e)

 

# 时间同步
0,10,20,30,40,50 * * * * ntpdate time.windows.com

 

过了一阵,发现时间并没有同步,而单独执行命令就可以。让命令执行结果输出到文件中试试:

 

# 时间同步
0,10,20,30,40,50 * * * * ntpdate time.windows.com &>/var/log/ntpdate.log

 

又过了一阵,发现时间还是不准确。看了一下 /var/log/ntpdate.log,如下:

 

/bin/sh: ntpdate: command not found

 

在shell中直接执行,就不会有找不到命令的问题,使用全路径来执行命令应该就可以了。先找到 ntpdate 的确切路径:

[root@node18 ~]# whereis ntpdate
ntpdate: /sbin/ntpdate /usr/sbin/ntpdate /usr/share/man/man8/ntpdate.8.gz

 

用 crontab -e 修改任务:

 

# 时间同步
#0,10,20,30,40,50 * * * * ntpdate time.windows.com &>/var/log/ntpdate.log
0,10,20,30,40,50 * * * * /sbin/ntpdate time.windows.com &>/var/log/ntpdate.log

 

保存

crontab: installing new crontab
[root@node18 ~]#
[root@node18 ~]#
[root@node18 ~]# date
2012年 07月 29日 星期日 02:48:13 CST
[root@node18 ~]# date
2012年 07月 29日 星期日 02:48:49 CST
[root@node18 ~]# date
2012年 07月 29日 星期日 02:49:46 CST
[root@node18 ~]# date
2012年 07月 30日 星期一 09:27:37 CST

时间同步了。
[root@node18 ~]# cat /var/log/ntpdate.log
30 Jul 09:26:33 ntpdate[6928]: step time server 65.55.21.19 offset 110191.229893 sec

 

总结两点:

(1)在 crontab 中设置了任务,要进行确认;

(2)crontab 中的命令尽量使用完整路径,避免执行时找不到。

 

 

 

 

 

Linux下使用ntpdate进行时间同步 阅读详情

相关推荐

linux crontab+ntpdate同步时间

发现服务器时间错了,设置下定时任务。 crontab -u root -e # 编辑内容 加入以下语句 每十分钟同步一次时间 */10 * * * * /usr/sbin/ntpdate ntp1.aliyun.com 第二天发现不起作用。 手动设置下,执行一下语句。 /usr/sbin/ntpdate ntp1.aliyun.com 发现报错如下: 21 Sep 14:39:09 ntpdate[24744]: the NTP socket is in use, exiting 解决方法:停止ntpd service ntpd stop crontab 定时任务还需要观察几天 参考:

Linux环境:ntpdate命令无法同步时间问题

1、背景:使用date -s 设置时间时,退出之后重新登录仍然发现时间是修改后的时间,与服务器或真实时间不同步 2.使用ntpdate命令同步时间,ntpdate time.ntp.org,发现不成功,ping time.ntp.org不成功,但ping www.baidu.com 是成功的,说明不是自身网络问题; 3.ping time.nist.gov成功,那么可以使用ntpdate tim...

weixin_34214500的博客 6027

uniapp 使用摄像头 live-pusher (APP)

uniapp 中开发 app 时使用live-pusher踩过的坑

随身笔记 1万+

crontab ntpdate不生效的问题

很久之前发现多台服务器直接时间不同步,导致了很多业务问题。决定采用ntpdate来进行时间同步。 ntpdate ntp.aliyun.com 单独执行没有问题。写在sh脚本中执行也没有问题。 但是时间同步应该需要周期性执行,保证同步,所以使用crontab周期性执行ntpdate,但是发现在crontab里并不会执行!!! 最后发现的问题是ntpdate的路径问题,必须在crontab里

kobep的专栏 4764

ubuntu 18.04 + Kimera slam 安装与demo测试

环境:opencv 3.4.12,其他的都是按照文档下载的。 首先进行组件的安装 一、Kimera-VIO 安装参考文档:https://github.com/MIT-SPARK/Kimera-VIO/blob/master/docs/kimera_vio_install.md 按照文档装就好,在安装过程中碰到如下问题: 0、make 过程很卡,不要用所有的核 1、cmake过程中卡下载 ORBvoc.zip ,手动下载这个文件,解压,将里面的3个文件,放到/Kimera-VIO/vocabu.

dna葡萄糖的博客 3628

告别实车测试:手把手教你用Vector VT平台搭建OBC/DCDC的HIL测试台架

本文详细介绍了如何利用Vector VT平台搭建新能源汽车OBC/DCDC的HIL测试台架,涵盖硬件选型、模型部署到自动化测试的全流程。通过HIL仿真测试技术,工程师可以高效验证动力域关键部件,大幅缩短开发周期并降低成本,特别适合新能源汽车三电系统的开发验证。

weixin_42659194的博客 338

树莓派使用ntpdate校准时间无效的一种情况和解决办法

树莓派不像PC的主板那样还带个电池用于关机之后的计时,每次都是板子开机之后重新计时,网友一般提供的方法就是用 ntpdate 联网校准时间。简单说一下我在树莓派2上安装这个服务后,时间没有校准的一个情况,以及解决的办法,准确来说,这只是在其他人的安装教程上做了一些补充。

u010940020的专栏 8531

双足步行机器人的ZMP与CoP检测

静态步行与动态步行   机器人步态分为静态步行和动态步行。当机器人做静态步行运动时,身体的各个部分运动速度很小,机器人的整体稳定性较易控制。静态步行稳定性采用机器人的重心地面投影点(Center of Gravity,简称CoG)作为稳定性标准,这种判定方法适用于运动较为缓慢的情况。如果机器人采用的是一种高速运动的步行方式,则称之为动态步行。当机器人进行动态步行时,其重心的位置和加速度的大小时...

weixin_34112208的博客 5906

Linux时间同步不生效(ntpdate ntp1.aliyun.com)

linux时间不同步问题

binglei_he的博客 1425

【49】软考软件设计师——冲刺复盘:高频易错点与应试策略|复盘清单+应试技巧

本文是《软件设计师·50讲通关|从零基础到工程师职称》专栏第49篇,属于**模块六:冲刺与模拟**终篇,聚焦考前最后阶段的“精准复盘+应试提分”。全文围绕“高频易错点清零、答题时间优化、应急处理落地”三大核心,梳理9大知识领域的典型易错点(附避坑技巧)、优化版答题时间分配(含取舍策略)、考中全场景应急方案,配套可直接使用的“复盘清单”和“应试技巧手册”,帮助考生在最后阶段查漏补缺、固化得分逻辑,避免因低级错误丢分,以“稳、准、快”的状态应对考试。下一篇第50篇(终章)将进行全专栏知识体系回顾、考试策略总结

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 439

即插即用篇 | 手把手教你 YOLOv11 添加注意力机制 | 适用于【检测任务】【分类任务】【分割任务】【关键点任务】| 20+ 种全打通!

即插即用篇 | 手把手教你 YOLOv11 添加注意力机制 | 适用于【检测任务】【分类任务】【分割任务】【关键点任务】| 20+ 种全打通!

Coding... 2831

crontab设置同步标准时间无效的解决方法

问题描述: crontab -e设置每分钟同步标准时间后,虽然在服务器日志/ var/log/messages显示ntpdate us.pool.ntp.org;hwclock -w,过段时间后又出现了延迟,与其他服务器时间不一致,导致数据库日志那块客户提交时间大于发送运营商时间。 问题分析: crontab设置了自动同步时间后,虽然在服务器日志/ var/log/messages显示ntp

胡威的技术博客 4952

如何使用Python爬取并保存网页上的所有附件

爬虫(Crawler)是一种自动化程序,它通过模拟人工访问网页并下载网页上的数据或文件,常用于数据采集和分析。爬虫通常以“爬取”的形式自动浏览和提取网页中的各种信息。本文详细介绍了如何使用Python爬取并保存网页中的附件文件,涵盖了网页解析、文件下载、多线程与异步优化等内容。希望通过本文的讲解,能够帮助你理解并掌握附件爬取的技巧。在实际应用中,爬虫开发不仅需要解决技术问题,还要遵守网络道德和法律法规,避免不当使用爬虫造成负面影响。

2201_76125261的博客 965

linux同步时间命令crontab,为什么在crontab中使用ntpdate同步时间无效?

在一台 VirtualBox 上安装的 CentOS 5.8 系统上,时间不准确,一天能差上好几个小时,每次测试与时间相关的程序时,总得先去调整时间。于是在crontab中设置了一个定时任务:(crontab -e)# 时间同步0,10,20,30,40,50 * * * * ntpdate time.windows.com过了一阵,发现时间并没有同步,而单独执行命令就可以。让命令执行结果输出到文...

weixin_42174098的博客 859

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

NTP时间同步服务器设置

ntp时间服务器搭建

lakelise的专栏 6544

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Linux服务器时间同步——ntpdate

在Linux系统中同步时间时,需要了解ntpdate这个命令,默认该命令在主流的Linux发行版中都有安装,默认安装路径/usr/sbin/ntpdate。以下操作皆在root帐号下进行,如果使用非root帐号,则需要该帐号为sudo用户能进行root权限的操作。

qq_40001822的博客 1万+

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

ntpdate同步更新时间

ntpdate同步更新时间 知识预览 1、安装ntpdate 2、date命令 3、ntpdate命令 4、ntp常用服务器 5、加入crontab  Linux服务器运行久时,系统时间就会存在一定的误差,一般情况下可以使用date命令进行时间设置,但在做数据库集群分片等操作时对多台机器的时间差是有要求的,此时就需要使用ntpdate进行时间同步 回到顶部 1、安装ntpdate ...

谦怀 1万+

ntpd 和ntpdate的区别 以及系统时间 硬件时间 及时间同步 crontab –e

ntpd 和ntpdate的区别 以及系统时间 硬件时间 及时间同步 crontab –e 1.首先crontab 命令 介绍 1.crontab命令常见于Unix和Linux的操作系统之中,用于设置周期性被执行的指令 2.该命令从标准输入设备读取指令,并将其存放于"crontab"文件中,以供之后读取和执行。 在Linux系统中,Linux任务调度的工作主要分为以下两类: 1、系统执行的工...

zengxianglei的博客--手指星辰 奈何天! 3738

linux时间同步(使用ntpdate+crontab)

linux 的系统时间的准确性很重要,比如java 的new Date();取的就是服务器的系统时间。 1.下载安装ntpdate yum -y install ntp ntpdate 2.设置系统时间和网络时间同步(cn.pool.ntp.org 为ntp时间服务器的地址,也可以换成其他的地址ntp2.aliyun.org) ntpdate cn.pool.ntp.org 3.上面的命令只同步了...

zhengxiaoya2017的博客 3391

使用ntpdate同步时间

1.安装ntpdate  yum install ntpdate 2.sudo ntpdate -u 133.100.11.8 //同步到日本的服务器时间 3.ntpdate –d 133.100.11.8 4.配置每一分钟自动同步一次         crontab还是大有学问的,定时功能就由它来控制,需要确保crond服务启用,今天只使用它的第一分钟执行特定脚本功能。

风口的猪2016 2976

Linux ntpdate同步网络时间

自己的Linux服务器的时间和PC机上的时间不太对,打log的时间对不上,不太方便调式信息的判断,因此需要同步一下Linux服务器的时间和自己Windows的时间,两者一致,才方便调式的查看呢。 同步网络时间 在Linux下,我们可以使用ntpdate进行网络时间的同步,而不是我们自己去设置时间。这个命令的使用很简单, ntpdate 0.cn.pool.ntp.org 另外网络时间同步和时区是...

This is oH2Oo 3306

linux ntpdate 查看同步时间,linux ntp ntpdate 同步时间

ntp同步时间实验服务端IP192.168.1.101客户端192.168.1.88一.登录server端1.首先配置ntpd服务vi /etc/ntp.conf配置文件中一般有restrict default语句,#掉后选择,以下2种的一种restrict default nomodify notrap noquery#默认允许所有可连接客户端ntpdate到本机restrict de...

weixin_42468580的博客 3238

linux ntp时间立即同步命令_linux时间同步,ntpd、ntpdate

一、window与linux系统时间介绍在Windwos中,系统时间的设置很简单,界面操作,通俗易懂。而且设置后,重启,关机都没关系。系统时间会自动保存在Bios的时钟里面,启动计算机的时候,系统会自动在Bios里面取硬件时间,以保证时间的不间断。但在Linux下,默认情况下,系统时间和硬件时间,并不会自动同步。在Linux运行过程中,系统时间和硬件时间以异步的方式运行,互不干扰。硬件时间的运行,...

weixin_42244017的博客 1万+

ntpdate:设置服务器时间定期同步

背景 在后端服务运行过程中,有时会遇到一个时间不同步的问题,即服务器时间对比当前时间会有滞后或超前。 这种时间不同步导致某些软件服务问题,例如: 1. 服务日志打印的时间不准,导致查问题比较麻烦。 2. 在服务写入数据到数据库或者其他中间件的时候,时间戳不对,导致页面显示异常 3. 集群化服务在不同机器节点上的时间不一致,导致集群状态异常 那如何解决时间同步的问题呢?我们可以使用ntpdate定期同步服务器时间 设置过程 安装ntpdate #Ubuntu apt install -y

公众号-测试生财 2169

Linux使用ntpdate同步系统时间

Linux使用ntpdate同步系统时间

gong_wejoy的专栏 3088
上一篇: 合并源代码到一个文件的脚本
下一篇: 使用nmap扫描服务器端口的一次操作
codingstandards
博客等级 码龄16年 12粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值