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

Linux限定网络和工具环境下时间同步

使用curl或wget工具同步某网站时间到本地环境。

使用curl工具

#!/bin/bash# Replace 'example.com' with the domain you want to query
url="http://example.com"# Fetch HTTP header and extract Date field
date_str=$(curl -sI "$url" | grep -i "^Date:" | sed 's/Date: //I')if [ -n "$date_str" ]; then# Set system date using the fetched datesudo date -s "$date_str"# Sync hardware clock with system timesudo hwclock --systohcecho "System time synchronized with $url and hardware clock updated"
elseecho "Failed to fetch date from $url"
fi

使用wget工具

#!/bin/bash# Replace 'example.com' with the domain you want to query
url="http://example.com"# Fetch HTTP header and extract Date field
date_str=$(wget --server-response -O /dev/null "$url" 2>&1 | grep -i "^  Date:" | sed 's/^  Date: //I')if [ -n "$date_str" ]; then# Set system date using the fetched datesudo date -s "$date_str"# Sync hardware clock with system timesudo hwclock --systohcecho "System time synchronized with $url and hardware clock updated"
elseecho "Failed to fetch date from $url"
fi
http://www.lryc.cn/news/303292.html

相关文章:

  • SQL Server查询计划(Query Plan)——文本查询计划
  • 2024年2月的TIOBE指数,go语言排名第8,JAVA趋势下降
  • 机器人十大前沿技术(2023-2024年)
  • Spring: MultipartFile和File的区别
  • ncnn之三(补充):window环境下vs2022安装ncnn+protobuf
  • 第五篇【传奇开心果系列】Python文本和语音相互转换库技术点案例示例:详细解读pyttsx3的`preprocess_text`函数文本预处理。
  • logback实践
  • 深入理解java虚拟机---自动内存管理
  • 粉笔规范词积累(文化发展)
  • 如何在Ubuntu部署Emlog,并将本地博客发布至公网可远程访问
  • Axios
  • 数据仓库选型建议
  • 每日一题——LeetCode1470.重新排列数组
  • 网络安全--网鼎杯2018漏洞复现(二次注入)
  • CSS篇--transform
  • 阿里云国际-在阿里云服务器上快速搭建幻兽帕鲁多人服务器
  • vite 快速搭建 Vue3.0项目
  • 深入理解Python爬虫的Response对象
  • centos7下docker的安装
  • Excel SUMPRODUCT函数用法(乘积求和,分组排序)
  • C#上位机与三菱PLC的通信08---开发自己的通讯库(A-1E版)
  • ABAQUS应用04——集中质量的添加方法
  • [嵌入式系统-24]:RT-Thread -11- 内核组件编程接口 - 网络组件 - TCP/UDP Socket编程
  • 【ansible】认识ansible,了解常用的模块
  • 【LeetCode】升级打怪之路 Day 01:二分法
  • 单片机stm32智能鱼缸
  • 面试经典150题——生命游戏
  • 【C++】C++11下线程库
  • 面试经典150题——矩阵置零
  • 多端开发围炉夜话