码迷,mamicode.com
首页 > 其他好文 > 详细

第二阶段 定时任务显示日期

时间:2018-11-25 14:31:13      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:定时   eth   esc   new   linux   scripts   使用   解决   mkdir   

[BEGIN] 2018/11/12 15:05:16
 
案列:每分钟显示当前系统的时间年-月 日_周和当前系统的IP地址,追加到/tmp/ip.log 中
[2018/11/12 15:09:16] [root@oldboy-200 ~]# date +%F_%w
[2018/11/12 15:09:16] 2018-11-12_1
[2018/11/12 15:09:20] [root@oldboy-200 ~]# ifconfig eth0|awk -F "[: ]+" ‘NR==2{print $4}‘
[2018/11/12 15:09:20] 10.0.0.200
[2018/11/12 15:10:40] [root@oldboy-200 ~]# vim /server/scripts/ip.sh
[2018/11/12 15:11:01] [root@oldboy-200 ~]# cat /server/scripts/ip.sh
[2018/11/12 15:11:01] #!/bin/bash
[2018/11/12 15:11:01] #desc(描述) show ip address
[2018/11/12 15:11:01] #author:yangjuncheng
[2018/11/12 15:11:01] #time:    20181121
[2018/11/12 15:11:01] date +%F_%w
[2018/11/12 15:11:15] [root@oldboy-200 ~]# sh /server/scripts/ip.sh
[2018/11/12 15:11:15] 2018-11-12_1
[2018/11/12 15:11:15] 10.0.0.200
[2018/11/12 15:13:56] [root@oldboy-200 ~]# /bin/sh /server/scripts/ip.sh
[2018/11/12 15:13:56] 2018-11-12_1
[2018/11/12 15:13:56] 10.0.0.200
[2018/11/12 15:15:18] [root@oldboy-200 ~]# #/bin/sh /server/scripts/ip.sh(/bin/sh方便操作)
2018/11/12 15:16:30] [root@oldboy-200 ~]# /bin/sh /server/scripts/ip.sh >>/tmp/ip.log
[2018/11/12 15:16:45] [root@oldboy-200 ~]# cat /tmp/ip.log
[2018/11/12 15:16:45] 2018-11-12_1
[2018/11/12 15:16:45] 10.0.0.200
[2018/11/12 15:17:35] [root@oldboy-200 ~]# #3.写到定时任务里面
[2018/11/12 15:17:35] You have new mail in /var/spool/mail/root
[2018/11/12 15:18:25] [root@oldboy-200 ~]# crontab -e
[2018/11/12 15:27:28] crontab: installing new crontab
[2018/11/12 15:27:35] [root@oldboy-200 ~]# crontab -l
[2018/11/12 15:27:35] # touch /tmp/test
[2018/11/12 15:27:35] # touch yangjuncheng is linux  student
[2018/11/12 15:27:35] 30 8 * * * go to bed
[2018/11/12 15:27:35] ##this is getup time at
[2018/11/12 15:27:35] 00 00 * * * go sleep
[2018/11/12 15:27:35] ### this is test ntp
[2018/11/12 15:27:35] */1 * * * *  /usr/sbin/ntpdate ntp1.aliyun.com    >/dev/null 2>&1
[2018/11/12 15:27:35] #this is test
[2018/11/12 15:27:35]
[2018/11/12 15:27:35] 00 23,00-07/1 * * * mkdir test
[2018/11/12 15:27:35] #this is test date scripts
[2018/11/12 15:27:35]
[2018/11/12 15:27:35] * * * * * /bin/sh /server/scripts/date.sh  >>/tmp/test.log
[2018/11/12 15:27:35] # test ce shi jiao ben
[2018/11/12 15:27:35] * * * * *  /bin/sh touch /tmp/testa.txt >/mnt/oldboy 2>&1
[2018/11/12 15:27:35] # this is print date scripts
[2018/11/12 15:27:35] * * * * *  /bin/sh /tmp/date.sh >>/mnt/date.log 2>&1
[2018/11/12 15:27:35]
[2018/11/12 15:27:35] # print date + ip file by  lee(人名) at 20181112
[2018/11/12 15:27:35]  * * * * * /bin/sh /server/scripts/ip.sh >>/tmp/ip.log         2>&1
[2018/11/12 15:27:35] #(注意先写五个*号,然后把命令原封不动的复制到计划任务里面,因为是追加到ip.log 日志里面所以后面要加2>&1)
[2018/11/12 15:27:35]  
[2018/11/12 15:28:51] [root@oldboy-200 ~]# tail -f /var/log/cron
Nov 12 15:50:01 oldboy-200 CROND[3753]: (root) CMD (/bin/sh /server/scripts/ip.sh >>/tmp/ip.log   
[2018/11/12 15:50:02] Nov 12 15:50:01 oldboy-200 CROND[3753]: (root) CMD (/bin/sh /server/scripts/ip.sh >>/tmp/ip.log         2>&1)
[2018/11/12 15:29:51] [root@oldboy-200 ~]# # 检查定时任务的日志
[2018/11/12 15:30:38] [root@oldboy-200 ~]# tail -f /tmp/ip.log
[2018/11/12 15:30:38] 2018-11-12_1
[2018/11/12 15:30:38] 10.0.0.200
[2018/11/12 15:30:38] 2018-11-12_1
2018/11/12 15:31:12] [root@oldboy-200 ~]# tail -f /tmp/ip.log
[2018/11/12 15:31:30] [root@oldboy-200 ~]# #检查文
[2018/11/12 15:36:50] [root@oldboy-200 ~]# vim /server/scripts/ip.sh
[2018/11/12 15:38:52] [root@oldboy-200 ~]# tail -f /tmp/ip.log
[2018/11/12 15:38:52] 2018-11-12_1
[2018/11/12 15:41:15] [root@oldboy-200 ~]# which ifconfig
[2018/11/12 15:41:15] /sbin/ifconfig
[2018/11/12 15:43:07] [root@oldboy-200 ~]# # 因为ifconfig /sbin下,PATH 环境变量只认识/bin /usr/bin 这两个路径
[2018/11/12 15:43:57] [root@oldboy-200 ~]# which ntpdate
[2018/11/12 15:43:57] /usr/sbin/ntpdate
[2018/11/12 15:49:42] [root@oldboy-200 ~]# # 因为ifconfig /sbin下,PATH 环境变量只认识/bin /usr/bin 这两个路径,也就是说其它路径的脚本定时任务是不认识的,解决的办法就是在在脚本里面使用绝对路径就行。
[2018/11/12 15:50:01] [root@oldboy-200 ~]# tail -f /var/log/cron
[2018/11/12 15:50:30] [root@oldboy-200 ~]# tail -f /tmp/ip.log
[2018/11/12 15:50:30] 2018-11-12_1
[2018/11/12 15:50:30] 10.0.0.200
[2018/11/12 15:50:30] 2018-11-12_1
 
 

第二阶段 定时任务显示日期

标签:定时   eth   esc   new   linux   scripts   使用   解决   mkdir   

原文地址:https://www.cnblogs.com/yangjuncheng0826/p/10015386.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!