时间定时同步


修改系统时间由三种方法:

一、修改时区

  1. cp /etc/localtime /etc/localtime.bak
  2. ln -svf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  3. #修改为中国的东八区
  4. vim /etc/sysconfig/clock
  5. ZONE="Asia/Shanghai"
  6. UTC=false
  7. ARC=false
  8. #与时间服务器同步
  9. ntpdate ntp服务器的ip

二、配置新的时间

  1. #日期设定
  2. date -s 2013/09/26
  3. #时间设定
  4. date -s "11:47:06"
  5. date -s "12:00:00 2013-12-06"
  6. ....
  7. #date是显示的系统的OS时间
  8. #clock是显示的BIOS的时间
  9. #查看硬件的时间
  10. hwclock [-rw]
  11. -r 查看现有BIOS时间。默认为-r参数
  12. -w 将现在的linux系统时间写入BIOS
  13. -s systohc)将硬件时间调整为和目前的系统时间一半

三、时间自动同步

  1. #1.开机自动网络校时
  2. cat /etc/rc.d/rc.local
  3. /usr/sbin/ntpdate -u 192.168.10.80
  4. #2.设置定时计划任务
  5. #yum install -y ntpdate (yum安装时间同步命令)
  6. crontab -e
  7. #加入内容
  8. */5 * * * * root ntpdate 192.168.10.80 #每隔五分钟与时间服务器同步一次时间

日志定时清理


清理日志脚本

  1. #!/bin/bash
  2. date >>/home/wdhis/logs/catalina.out
  3. echo "del file start....." >> /home/wdhis/logs/catalina.out
  4. find /home/wdhis/logs/*/*.log -mtime +14 -name "*.log" -exec rm -rf {} \; >> /home/wdhis/logs/catalina.out
  5. find /home/wdhis/Server/dubbo-consumer/dubbo-emis-tomcat/logs/* -mtime +14 -name "*" -exec rm -rf {} \; >> /home/wdhis/logs/catalina.out
  6. find /home/wdhis/Server/dubbo-consumer/dubbo-mmis-tomcat/logs/* -mtime +14 -name "*" -exec rm -rf {} \; >> /home/wdhis/logs/catalina.out
  7. find /home/wdhis/Server/dubbo-consumer/dubbo-outpat-tomcat/logs/* -mtime +14 -name "*" -exec rm -rf {} \; >> /home/wdhis/logs/catalina.out
  8. find /home/wdhis/Server/dubbo-consumer/dubbo-core-tomcat/logs/* -mtime +14 -name "*" -exec rm -rf {} \; >> /home/wdhis/logs/catalina.out
  9. find /home/wdhis/Server/dubbo-consumer/dubbo-plugs-tomcat/logs/* -mtime +14 -name "*" -exec rm -rf {} \; >> /home/wdhis/logs/catalina.out
  10. echo " " > /home/wdhis/Server/dubbo-consumer/wdhis-emis-svr/logs/catalina.out
  11. echo " " > /home/wdhis/Server/dubbo-consumer/wdhis-mmis-svr/logs/catalina.out
  12. echo " " > /home/wdhis/Server/dubbo-consumer/wdhis-outpat-svr/logs/catalina.out
  13. echo " " > /home/wdhis/Server/dubbo-consumer/wdhis-core-svr/logs/catalina.out
  14. echo " " > /home/wdhis/Server/dubbo-consumer/wdhis-plugs-svr/logs/catalina.out
  15. echo "del file end" >> /home/wdhis/logs/catalina.out
  16. echo "del file provide nohup" >> /home/wdhis/logs/catalina.out
  17. echo " " > /home/wdhis/Server/dubbo-provider/wdhis-medicare-svr/nohup.out
  18. echo " " > /home/wdhis/Server/dubbo-provider/wdhis-outplugs-svr/nohup.out
  19. echo " " > /home/wdhis/Server/dubbo-provider/wdhis-payment-svr/nohup.out
  20. echo " " > /home/wdhis/Server/dubbo-provider/wdhis-report-svr/nohup.out
  21. echo "del file end nohup" >> /home/wdhis/logs/catalina.out
  22. date >> /home/wdhis/logs/catalina.out
  23. #设置脚本执行权限
  24. chmod +x delete-logs.sh

将脚本加入定时任务

  1. [root@admin wdhis]# crontab -e
  2. crontab: installing new crontab
  3. [root@admin wdhis]# crontab -l
  4. #定时清理云HIS日志,在每隔十五天的0点
  5. * 0 */15 * * wdhis /home/wdhis/logs/delete_log.sh