当前位置: 首页 > news >正文

Linux815 shell:while

问题

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

Last login: Sun Aug 10 15:25:17 2025 from 192.168.235.1
[code@samba ~]$ rdate -s 192.168.235.100
rdate: couldn't connect to host 192.168.235.100: Connection refused

在这里插入图片描述

[code@samba ~]$ ntpdate 192.168.235.100
15 Aug 20:33:14 ntpdate[60744]: bind() fails: Permission denied
[code@samba ~]$

在这里插入图片描述

[root@samba caozx26]# ntpdate 192.168.235.100
15 Aug 20:38:49 ntpdate[62790]: no server suitable for synchronization found

在这里插入图片描述
192.168.235.100

[root@backup caozx26]# yum install -y ntpdate
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
lcoal                                             | 3.6 kB     00:00
软件包 ntpdate-4.2.6p5-29.el7.centos.2.x86_64 已安装并且是最新版本
无须任何处理
[root@backup caozx26]# ntpdate
15 Aug 20:45:02 ntpdate[83182]: no servers can be used, exiting

192.168.235.10

[root@samba caozx26]# ntpdate 192.168.235.100
15 Aug 20:47:45 ntpdate[64318]: no server suitable for synchronization found
#!/bin/bash
count=0
ntp_server=192.168.235.100
while true
dontpdate -u $ntp_server>/dev/null 2>&1if [ $? -ne 0 ];thenecho "system date failed"|mail -s 'check system date' root@localhostelselet count++if [ $[$count%100] -eq 0 ];thenecho "system date successfull" |mail -s 'check system date' root@localhost && count=0fifi
sleep 3
done

在这里插入图片描述

  let count++if [ $[$count%100] -eq 0 ];thenecho "system date successfull" |mail -s 'check system date' root@localhost && count=0fi

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

[root@samba caozx26]# cat ntp1.sh
#!/bin/bash
count=0
ntp_server=192.168.235.100
ntpdate -u $ntp_server
while true
do
if [ $? -ne 0 ];then
echo "ntpdate unsuccessfully"|mail -s "no" root@localhost
else
let count++
if [ $((count%100)) -eq 0 ];then
echo "ntpdate successfully"|mail -s "yes" root@localhost && count=0
fi
fi
sleep 3
done
[root@samba caozx26]# cat ntp1.sh
#!/bin/bash
count=0
ntp_server=192.168.235.100
while true
do
ntpdate -u $ntp_server
if [ $? -ne 0 ];then
echo "ntpdate unsuccessfully"|mail -s "no" root@localhost
else
let count++
if [ $((count%100)) -eq 0 ];then
echo "ntpdate successfully"|mail -s "yes" root@localhost && count=0
fi
fi
sleep 3
done

while true
在这里插入图片描述

记录

192.168.235.100

    ┌──────────────────────────────────────────────────────────────────────┐│                 • MobaXterm Personal Edition v23.2 •                 ││               (SSH client, X server and network tools)               ││                                                                      ││ ⮞ SSH session to backup@192.168.235.100                              ││   • Direct SSH      :  ✓                                             ││   • SSH compression :  ✓                                             ││   • SSH-browser     :  ✓                                             ││   • X11-forwarding  :(remote display is forwarded through SSH)  ││                                                                      ││ ⮞ For more info, ctrl+click on help or visit our website.            │└──────────────────────────────────────────────────────────────────────┘Last login: Sun Jun 29 13:43:56 2025 from 192.168.235.1
[backup@backup ~]$ ntpdate
15 Aug 20:42:59 ntpdate[82329]: no servers can be used, exiting
[backup@backup ~]$ yum install -y ntpdate
已加载插件:fastestmirror, langpacks
您需要 root 权限执行此命令。
[backup@backup ~]$ sudo su
[sudo] backup 的密码:
backup 不在 sudoers 文件中。此事将被报告。
[backup@backup ~]$ su - caozx26
密码:
上一次登录:六 621 04:40:02 CST 2025pts/0 上
[caozx26@backup ~]$ yum install -y ntpdate
已加载插件:fastestmirror, langpacks
您需要 root 权限执行此命令。
[caozx26@backup ~]$ sudo su
[sudo] caozx26 的密码:
[root@backup caozx26]# yum install -y ntpdate
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
lcoal                                             | 3.6 kB     00:00
软件包 ntpdate-4.2.6p5-29.el7.centos.2.x86_64 已安装并且是最新版本
无须任何处理
[root@backup caozx26]# ntpdate
15 Aug 20:45:02 ntpdate[83182]: no servers can be used, exiting
[root@backup caozx26]# yum install -y chrony
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 chrony-3.4-1.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@backup caozx26]# systemctl start chronyd
[root@backup caozx26]# systemctl enable chronyd
Created symlink from /etc/systemd/system/multi-user.target.wants/chronyd.service to /usr/lib/systemd/system/chronyd.service.
[root@backup caozx26]# cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3# Enable kernel synchronization of the real-time clock (RTC).
rtcsync# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2# Allow NTP client access from local network.
#allow 192.168.0.0/16# Serve time even if not synchronized to a time source.
#local stratum 10# Specify file containing keys for NTP authentication.
#keyfile /etc/chrony.keys# Specify directory for log files.
logdir /var/log/chrony# Select which information is logged.
#log measurements statistics tracking
[root@backup caozx26]# vim /etc/chrony.conf
[root@backup caozx26]# cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3# Enable kernel synchronization of the real-time clock (RTC).
rtcsync# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2# Allow NTP client access from local network.
#allow 192.168.0.0/16# Serve time even if not synchronized to a time source.
#local stratum 10# Specify file containing keys for NTP authentication.
#keyfile /etc/chrony.keys# Specify directory for log files.
logdir /var/log/chrony# Select which information is logged.
#log measurements statistics tracking
"allow 192.168.235.0/24"
[root@backup caozx26]# systemctl restart chronyd
Job for chronyd.service failed because the control process exited with error code. See "systemctl status chronyd.service" and "journalctl -xe" for details.
[root@backup caozx26]# chronyd -d -f /dev/null
2025-08-15T13:08:45Z chronyd version 3.4 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 +DEBUG)
2025-08-15T13:08:45Z Initial frequency -7.395 ppm
^C2025-08-15T13:08:53Z chronyd exiting
[root@backup caozx26]# ss -unlp | grep 123
[root@backup caozx26]# cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3# Enable kernel synchronization of the real-time clock (RTC).
rtcsync# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2# Allow NTP client access from local network.
#allow 192.168.0.0/16# Serve time even if not synchronized to a time source.
#local stratum 10# Specify file containing keys for NTP authentication.
#keyfile /etc/chrony.keys# Specify directory for log files.
logdir /var/log/chrony# Select which information is logged.
#log measurements statistics tracking
"allow 192.168.235.0/24"
[root@backup caozx26]# vim /etc/chrony.conf
[root@backup caozx26]# echo "allow 192.168.235.0/24" >>/etc/chrony.conf
[root@backup caozx26]# cat chrony.conf
cat: chrony.conf: 没有那个文件或目录
[root@backup caozx26]# cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3# Enable kernel synchronization of the real-time clock (RTC).
rtcsync# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2# Allow NTP client access from local network.
#allow 192.168.0.0/16# Serve time even if not synchronized to a time source.
#local stratum 10# Specify file containing keys for NTP authentication.
#keyfile /etc/chrony.keys# Specify directory for log files.
logdir /var/log/chrony# Select which information is logged.
#log measurements statistics tracking
allow 192.168.235.0/24
[root@backup caozx26]# systemctl restart chronyd
[root@backup caozx26]# systemctl status chronyd
● chronyd.service - NTP client/serverLoaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)Active: active (running) since 五 2025-08-15 21:12:20 CST; 46s agoDocs: man:chronyd(8)man:chrony.conf(5)Process: 91111 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)Process: 91104 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)Main PID: 91109 (chronyd)Tasks: 1CGroup: /system.slice/chronyd.service└─91109 /usr/sbin/chronyd815 21:12:20 backup.cn systemd[1]: Starting NTP client/server...
815 21:12:20 backup.cn chronyd[91109]: chronyd version 3.4 startin...
815 21:12:20 backup.cn chronyd[91109]: Frequency -7.395 +/- 5.174 ...
815 21:12:20 backup.cn systemd[1]: Started NTP client/server.
815 21:12:28 backup.cn chronyd[91109]: Selected source 95.111.202.5
815 21:12:28 backup.cn chronyd[91109]: Source 95.111.202.5 replace...
815 21:12:28 backup.cn chronyd[91109]: Selected source 139.199.214...
Hint: Some lines were ellipsized, use -l to show in full.
[root@backup caozx26]# netstat -tuln | grep 123
udp        0      0 0.0.0.0:123             0.0.0.0:*                    
[root@backup caozx26]# ls
公共  模板  视频  图片  文档  下载  音乐  桌面
[root@backup caozx26]# less /var/spool/mail/root
[root@backup caozx26]# less /var/spool/mail/root
[root@backup caozx26]#

192.168.235.10

    ┌──────────────────────────────────────────────────────────────────────┐│                 • MobaXterm Personal Edition v23.2 •                 ││               (SSH client, X server and network tools)               ││                                                                      ││ ⮞ SSH session to code@192.168.235.10                                 ││   • Direct SSH      :  ✓                                             ││   • SSH compression :  ✓                                             ││   • SSH-browser     :  ✓                                             ││   • X11-forwarding  :(remote display is forwarded through SSH)  ││                                                                      ││ ⮞ For more info, ctrl+click on help or visit our website.            │└──────────────────────────────────────────────────────────────────────┘Last login: Sun Aug 10 15:25:17 2025 from 192.168.235.1
[code@samba ~]$ rdate -s 192.168.235.100
rdate: couldn't connect to host 192.168.235.100: Connection refused
[code@samba ~]$ ntpdate 192.168.235.100
15 Aug 20:33:14 ntpdate[60744]: bind() fails: Permission denied
[code@samba ~]$ su - caozx26
密码:
上一次登录:日 8月 10 08:39:52 CST 2025pts/0 上
[caozx26@samba ~]$ sudo su
[sudo] caozx26 的密码:
[root@samba caozx26]# ntpdate 192.168.235.100
15 Aug 20:38:49 ntpdate[62790]: no server suitable for synchronization found
[root@samba caozx26]# ntpdate 192.168.235.100
15 Aug 20:47:45 ntpdate[64318]: no server suitable for synchronization found
[root@samba caozx26]# yum install -y ntpdate
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
local1                                            | 3.6 kB     00:00
软件包 ntpdate-4.2.6p5-29.el7.centos.2.x86_64 已安装并且是最新版本
无须任何处理
[root@samba caozx26]# ntpdate 192.168.235.100
15 Aug 20:54:49 ntpdate[66127]: no server suitable for synchronization found
[root@samba caozx26]# ntpdate -u 192.168.235.100
15 Aug 20:55:39 ntpdate[66425]: no server suitable for synchronization found
[root@samba caozx26]# ntpdate -u 192.168.235.100
15 Aug 21:13:56 ntpdate[66835]: adjust time server 192.168.235.100 offset 0.007213 sec
[root@samba caozx26]# vim ntp.sh
[root@samba caozx26]# cat ntp.sh
#!/bin/bash
count=0
ntp_server=192.168.235.100
while true
dontpdate -u $ntp_server>/dev/null 2>&1if [ $? -ne 0 ];thenecho "systemctl date failed"|mail -s 'check system date' root@localhostelselet count++if [ $[$count%100] -eq 0 ];thenecho "system date successfull" |mail -s 'check systemctl date' root@localhost && count=0fifi
sleep 3
done
[root@samba caozx26]# chmod +x ntp.sh
[root@samba caozx26]# ./ntp.sh
^C
[root@samba caozx26]# vim ntp.sh
[root@samba caozx26]# cat ntp.sh
#!/bin/bash
count=0
ntp_server=192.168.235.100
while true
dontpdate -u $ntp_server>/dev/null 2>&1if [ $? -ne 0 ];thenecho "system date failed"|mail -s 'check system date' root@localhostelselet count++if [ $[$count%100] -eq 0 ];thenecho "system date successfull" |mail -s 'check system date' root@localhost && count=0fifi
sleep 3
done
[root@samba caozx26]#
[root@samba caozx26]# vim ntp1.sh
[root@samba caozx26]# cat ntp1.sh
#!/bin/bash
count=0
ntp_server=192.168.235.100
ntpdate -u $ntp_server
while true
do
if [ $? -ne 0 ];then
echo "ntpdate unsuccessfully"|mail -s "no" root@localhost
else
let count++
if [ $((count%100)) -eq 0 ];then
echo "ntpdate successfully"|mail -s "yes" root@localhost && count=0
fi
fi
sleep 3
done
[root@samba caozx26]# vim ntp1.sh
[root@samba caozx26]# cat nup1.sh
cat: nup1.sh: 没有那个文件或目录
[root@samba caozx26]# cat ntp1.sh
#!/bin/bash
count=0
ntp_server=192.168.235.100
while true
do
ntpdate -u $ntp_server
if [ $? -ne 0 ];then
echo "ntpdate unsuccessfully"|mail -s "no" root@localhost
else
let count++
if [ $((count%100)) -eq 0 ];then
echo "ntpdate successfully"|mail -s "yes" root@localhost && count=0
fi
fi
sleep 3
done
[root@samba caozx26]#
http://www.xdnf.cn/news/1303417.html

相关文章:

  • 口播数字人免费API调用方案
  • Elasticsearch赋能规章制度智能检索:从海量文档到秒级响应
  • linux-----------------锁
  • mysql启动超时
  • 本地生活|MallBook 分账赋能浙江本地生活服务平台,助力实现资金流转效率与合规性的双提升!
  • 高通vendor app访问文件
  • LeetCode hot 100 day2
  • AAAI爆款:目标检测新范式,模块化设计封神之作
  • 办公效率提升指南:完成重复任务自动化
  • 【自动化测试】通过AI技术如何自动建设接口自动化用例(有关必回)
  • GPT-5 官方前瞻:它将如何重塑你的数字生活?
  • 5G赋能井下“毛细血管”:巴拉素煤矿零散排水点智能监控系统
  • [激光原理与应用-283]:理论 - 波动光学 - 电磁波概述
  • 架构需求规格说明(ARD):项目成功的隐形引擎
  • 【nginx端口】修改nginx全局模块、子模块配置,重启后依然监听80端口
  • YOLOv8目标检测网络结构理论
  • 笔试——Day39
  • DevEco Studio 6.0.0 元服务页面跳转失败
  • Spring事物
  • 智能座舱软件架构设计的宏观决策框架
  • 【自动驾驶】自动驾驶概述 ② ( 自动驾驶技术路径 | L0 ~ L5 级别自动驾驶 )
  • 数据结构:二叉树的表示方式(Representation of Binary Trees)
  • 【测试工具】JMeter基本使用及MySQL数据库压力测试
  • Baumer高防护相机如何通过YoloV8深度学习模型实现驾驶员疲劳的检测识别(C#代码UI界面版)
  • python的美食交流社区系统
  • @[TOC](计算机是如何⼯作的) JavaEE==网站开发
  • 前端性能优化工具Performance面板实战指南
  • 【swift开发】SwiftUI概述 SwiftUI 全面解析:苹果生态的声明式 UI 革命
  • 【C#补全计划】事件
  • 【2D】圆上数值积分(半径方向用高斯积分减少点数)